jsonschema icon indicating copy to clipboard operation
jsonschema copied to clipboard

Beyond validation

Open dbinit opened this issue 13 years ago • 3 comments

Hi, great project.

Do you have any plans to provide more than validation with your project? In particular, it would be great if the schema+instance walking were abstracted so that it could be used for other things.

In my case, I would like to apply transformations before validation.

dbinit avatar May 16 '13 03:05 dbinit

Thanks :).

This project is going to stick with just implementing the spec, but I do have similar ideas and desires as you might (and a few other people have expressed interest), so recently we've started up https://github.com/Julian/Seep which will handle the layer on top of just strictly validation. I encourage you to check that out and voice whatever ideas you have in mind, since right now it's in planning stages on two vomited-out Wiki pages.

I don't have tons of time right now, so my desire to make time for Seep will likely be motivated by the presence of others who are willing to do some of the chunks of work on that project – or more accurately, who are willing to do some organizing and planning, and administrating :D. Although, at least with the ideas I currently have there none of that is really that difficult so far.

Julian avatar May 17 '13 01:05 Julian

Hi there,

Our team have two use cases not covered by jsonschema that we're going to need in short order. The first is as described by this ticket – the ability to walk the schema. The second is access to the default property.

In both cases my only apparent option is to cutpaste the guts of jsonschema and produce such an abstraction myself.

Some kind of schema visitor is useful in a bunch of circumstances, for example:

  • Enumerating the path to every possible scalar field in a definition (e.g. for GUI-based CSV export)
  • Producing transforms of the schema useful for storage (for example, to produce compact 2-8 byte encodings for JSON objects that would otherwise be 80-200 bytes each).

I admire your work on seep – but it seems unless you plan to mostly reimplement this module as part of seep, some kind of generalization of jsonschema internals will be needed at some point :)

dw avatar Jun 04 '13 05:06 dw

I'm not sure I've fully understood the two things you're asking for, but they certainly don't require copying and pasting any internals.

jsonschema has quite a decent extension API if I don't say so myself. It's partially documented here in the docs.

In particular, though schema traversals are really unspecial (it's a Python dict, you can traverse them as you always do) if you wanted to traverse them while the validation is occurring that's pretty much exactly what the extension API is for, and is how Seep works: https://github.com/Julian/Seep/blob/master/seep/core.py#L17

I don't know what kind of thing you want to do with ‛default` but whatever it is is probably possible in the same way. If what you want is to fill in defaults on your instance or whatever there's a FAQ entry that'd get you started here: https://python-jsonschema.readthedocs.org/en/latest/faq/

Hope this helps. Julian

Julian avatar Jun 04 '13 11:06 Julian