Download the PHP package philiprehberger/php-safe-json without Composer

On this page you can find all versions of the php package philiprehberger/php-safe-json. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-safe-json

PHP Safe JSON

Tests Latest Version on Packagist Last updated

Safe JSON parsing with exceptions, schema validation, and typed getters.

Requirements

Installation

Usage

Decoding JSON

Dot Notation for Nested Access

Nested Objects

Safe Decoding (No Exceptions)

Default Values

Nullable Accessors

Merging Objects

JSON Path Querying

Supported syntax: $ (root), .key (child), [0] (index), [*] (wildcard), ..key (recursive descent), [0:3] (slice), ['key'] (bracket notation).

JSON Diffing

Streaming Decode

Encoding

Serialization

API

SafeJson

Method Description
decode(string $json): JsonObject Decode JSON string, throws JsonDecodeException on failure
tryDecode(string $json): ?JsonObject Decode JSON string, returns null on failure
encode(mixed $data, int $flags = 0): string Encode to JSON string, throws on failure
tryEncode(mixed $data, int $flags = 0): ?string Encode to JSON string, returns null on failure
diff(string $jsonA, string $jsonB): array Compare two JSON strings and return differences
decodeStream(string $filePath): Generator Stream-decode a JSON array file, yielding elements one at a time

JsonObject

Method Description
string(string $key): string Get string value by key
int(string $key): int Get integer value by key
float(string $key): float Get float value by key (accepts integers)
bool(string $key): bool Get boolean value by key
stringOrNull(string $key): ?string Get string value or null if missing/wrong type
intOrNull(string $key): ?int Get integer value or null if missing/wrong type
floatOrNull(string $key): ?float Get float value or null if missing/wrong type
boolOrNull(string $key): ?bool Get boolean value or null if missing/wrong type
array(string $key): array Get array value by key
object(string $key): JsonObject Get nested JsonObject by key
get(string $key, mixed $default = null): mixed Get value without type enforcement
has(string $key): bool Check if key exists
merge(self $other): self Merge with another JsonObject (other overrides on conflict)
query(string $path): array Query data using JSON Path expression
toArray(): array Return underlying array
toJson(int $flags = 0): string Return JSON string

All key-based methods support dot notation for nested access (e.g., user.address.city).

JsonPath

Method Description
query(array $data, string $path): array Query data using JSON Path expression

JsonDiff

Method Description
diff(mixed $a, mixed $b, string $path = ''): array Compare two values and return list of differences

StreamDecoder

Method Description
decodeStream(string $filePath): Generator Stream-decode a JSON array file element by element

Exceptions

Exception Thrown When
JsonDecodeException Invalid JSON input
JsonEncodeException Failed to encode data
JsonKeyException Missing key or type mismatch

Development

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT


All versions of php-safe-json with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package philiprehberger/php-safe-json contains the following files

Loading the files please wait ...