webmozart / json Goto Github PK
View Code? Open in Web Editor NEWA robust JSON decoder/encoder with support for schema validation.
License: MIT License
A robust JSON decoder/encoder with support for schema validation.
License: MIT License
Hello :)
Is it actually planned to support PHP 8?
This project requires php ^5.3.3|^7.0
Thank you
Thanks for this library. I'm using it and now that I'm trying to use references in schemas I'm asking myself whether you not resolve references on purpose? See this gist for an example. Without doing the reference resolution the schema contains
"properties": {
"billing_address": {
"$ref": "#/definitions/address"
},
"shipping_address": {
"$ref": "#/definitions/address"
}
},
instead of
"properties": {
"billing_address": {
"type": "object",
"properties": {
"street_address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
}
},
"required": [
"street_address",
"city",
"state"
],
"id": "file:///srv/www/json-schema/schema-address.json#/definitions/address"
},
"shipping_address": {
"type": "object",
"properties": {
"street_address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
}
},
"required": [
"street_address",
"city",
"state"
],
"id": "file:///srv/www/json-schema/schema-address.json#/definitions/address"
}
}
Apart from the underlying library not supporting all cases of definitions
and $ref
usage I just wanted to make sure whether you're deviating intentionally from the README example of justinrainbow/json-schema.
Are you seriously?
https://github.com/webmozart/json/blob/master/src/JsonEncoder.php#L288
How about sharing file between multiple threads? You mush use something like this http://php.net/manual/en/function.flock.php
Hello!
For some reason, composer require webmozart/json
yields outdated package from Jan 14, which does not contain none of VersionFieldVersioner, SchemaUriVersioner, MigrationManager, MigratingConverter, JsonMigration, JsonConverter, ValidatingConverter, etc.
Please advise asap.
Following code:
$json = '{"int_overflow":9223372036854775807}';
$decoder = new JsonDecoder();
$decode = $decoder->decode($json);
Throws exception: json_decode(): integer overflow detected
. This should be translate from a big int to the string value.
I think most of your library is missing from the release. See release tag 1.2.2 here : https://github.com/webmozart/json/tree/a1fb3da904b8364e3db47eed68f76bfb6cd0031a/src
composer require webmozart/json
gives "webmozart/json": "^1.2"
, installs version 1.2.2
Comparing repository at tag 1.2.2 with master reveals obvious lack of code : https://github.com/webmozart/json/tree/master/src
res/meta-schema.json
could be mapped to /webmozart/json/meta-schema.json
and JsonValidator::loadSchema
should load Puli ressources
note: I have no idea how it could be done without introducing a BC break :/
Currently, the library requires version ^1.6
of justinrainbow/json-schema
. The current stable version is 5.2.0: https://packagist.org/packages/justinrainbow/json-schema
Is this correct for missing json/src/Conversion/JsonConverter.php file and other folders from 1.2.2 tag?
Hey @webmozart ,
I was looking for a way to handle json schema $ref
locally and was happy that your package provides a nice mechanism: https://github.com/webmozart/json#schemas
We have the latest version installed 1.2.2
but the JsonValidator looks different in this version. So I was confused. Wouldn't it be better to work on upcoming feature in a develop branch so that the README in the master branch reflects the latest released version instead of the next?
Hi,
I have empty keys in my json that represent empty values in dropdowns. When I use native json_decode
, empty keys are transformed to _empty_
string. This is a known PHP bug: https://bugs.php.net/bug.php?id=46600
So the following json decoded and encoded again is not the same as original:
$json = '{"test": {"": "foo"}}';
var_dump(json_encode(json_decode($json))); // "{"test":{"_empty_":"foo"}}"
Notice an _empty_
key instead of ''
key.
The same behaviour is when I use this package:
$encoder = new JsonEncoder();
$decoder = new JsonDecoder();
$decoded = $decoder->decode('{"test": {"": "foo"}}');
dump($decoded);
dump($encoder->encode($decoded));
// output
{#1316
+"test": {#1317
+"_empty_": "foo"
}
}
"{"test":{"_empty_":"foo"}}"
Do you have any recommendations on how to avoid this? I cant use assoc = true
because in my json there are many keys with empty objects that are converted back as arrays when you use assoc = true
For now I use an ugly solution with replacing all _empty_
keys with empty strings:
private function jsonEncode($content)
{
$jsonString = json_encode($content, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$fixedJsonString = str_replace('"_empty_":', '"":', $jsonString);
return $fixedJsonString;
}
This is not a bug report bug a general question about this library, validation and SCIM (https://tools.ietf.org/html/rfc7643).
Do you know if it is possible to use schemas described in the RFC7643 to validate SCIM resources using that library?
Herr webmozart, may I respectfully ask for a tag with the new shiny JsonValidator in it? Vielen dank.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.