Re: RFC Idea - json_validate() validate schema

From: Date: Wed, 01 Mar 2023 17:04:27 +0000
Subject: Re: RFC Idea - json_validate() validate schema
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-119644@lists.php.net to get a copy of this message
On Wed, Mar 1, 2023, at 6:06 AM, Jakub Zelenka wrote: > On Wed, Mar 1, 2023 at 11:44 AM juan carlos morales < > dev.juan.morales@gmail.com> wrote: > >> Hello Internals. >> >> I am thinking about improving the json_validate() function developed >> for php 8.3. >> >> The actual descriptions goes like this: >> >> json_validate(string $json, int $depth = 512, int $flags = 0): bool >> >> I am thinking about enhancing this function to also be able to >> validate against a JSON SCHEMA, giving us something like this: >> >> json_validate(string $json, int $depth = 512, int $flags = 0, string >> $json_schema = null): bool >> >> so, if the string is a valid JSON and also respects the schema ... then >> TRUE. >> >> What do you think ? >> >> > I'm actually working on this. Currently developing the schema parsing in > pure C implementation in my play C tool called jso. You can see progress > here: https://github.com/bukka/jso/commits/next . The plan is > to develop it > inside jso and then port it to jsond and then propose it for json ext > inclusion (that's how I developed the current parser). There is a lot of to > do as JsonSchema is quite complex (composition, JSON pointers, stream > integration for external pointers and more tricky bits) so this won't > likely be ready for 8.3 but should be ready for 8.4. I plan to introduce > some smaller things for 8.3 like better error reporting (error location > which I have already working in jso) and some other small additions. By the > way, the schema support won't be useful just for validation but also for > decoding and possibly encoding (sort of replacement for JsonSerializable). > Especially for decoding it can be further extended to allow class mapping. > We could also provide automatic generation of schema from class and support > attributes. I plan to propose all of this later as well but that might take > some time. > > Regards > > Jakub Ooo... This would be super userful, especially for some of the ideas I have floating about in the back of my head for new libraries. :-) I'm no help on the C implementation side but I'd be happy to collaborate on the user-space API design. That's something we'd want to get very-right the first time out, or else have just the primitives that allow us to do the not-slow bits in user-space. (Which will likely mean something more than just tacking an extra parameter onto json_validate().) --Larry Garfield

« previous php.internals (#119644) next »