4 ms·
I would strongly recommend that anyone looking into something like this first look at JSON Schema[1], which is a pretty widely adopted standard. We're doing ser
by o_____________o 11y ago
I would strongly recommend that anyone looking into something like this first look at JSON Schema[1], which is a pretty widely adopted standard. We're doing server and client validation with one set of rules, and there are lots of libraries that will clean up your data given a schema.
[1] http://json-schema.org/examples.html http://json-schema.org/examples.html
- sync 11y agoYep, it's really too bad all of these form builders out there invent their own DSL instead of using the JSON Schema standard.
- brotchie 11y agoI second this. On our backend we have a main service in Python and a few micro-services in Node. All of the JSON data flying between these services has JSON Schema definitions. We've built some express.js and wsgi middleware so that for a given route you can specify "Requests to this endpoint should follow schema {} responses from this endpoint should follow schema {}." Our middleware then validates all requests and responses against these schema. This works really well for us.
- zachrose 11y agoThat sounds nice. At my shop we have all of that except the live validation, and schemas almost inevitably fall behind. What happens when the validation fails? Also, which end does the validation, providers or consumers?
- msoad 11y agoI have some experience in this. Problem is, JSON Schema doesn't give you some attributes like order of properties for building the form. What makes sense is extending JSON Schema with optional properties that fill in things JSON Schema doesn't provide yet make it work with nothing but a JSON Schema. json-editor[1] does a very good job in this regard. Libraries like these are repeating what people have done already previously (classic JS framework DRY problem). They will need to solve a lot of corner cases to mature. Recursion, oneOf and some other JSON Schema properties are pretty hard to implement. [1] https://github.com/jdorn/json-editor https://github.com/jdorn/json-editor
- btown 11y agoIt's pretty easy to extend JSON Schema with all sorts of other metadata about how a UI should represent the data, or how automated tools should interact with records, making your JSON Schema the single source of truth for your entire data model. The cool thing is that you can actualy write a JSON Schema that extends http://json-schema.org/schema http://json-schema.org/schema which is the JSON Schema that describes JSON Schema, so you can validate that your use of your custom extensions to JSON Schema aren't misspelled or inconsistent. And that meta-schema can also be validated by http://json-schema.org/schema.. http://json-schema.org/schema... It's schemas all the way down! Getting back to the point, my company is using this exact approach in production, with Python and client-side Javascript consuming the same schema. We have a React component that essentially does what https://github.com/jdorn/json-editor https://github.com/jdorn/json-editor does, but customized for our organization. JSON Schemas make it so easy to add entirely new attributes to our data models and have them consistently validated across the board. Can't imagine doing it any other way.
- alexatkeplar 11y agoShameless plug - our Iglu Central is a central repository for commonly-used JSON Schemas. It's here: https://github.com/snowplow/iglu-central https://github.com/snowplow/iglu-central You can think of it like RubyGems.org or Maven Central but for storing vendored, versioned data schemas instead of code.