Is there json schema of json schema? - json

Is there JSON Schema of JSON Schema? In my app user can upload his JSON schema and I would like to validate it if it's a valid JSON Schema.

Yes. This is the meta-schema of JSON Schema draft-04. You can use it to validate whether a JSON is a valid JSON schema.

Yes - it is recommended that schemas reference the schema that they are implementing by declaring a "$schema" property. At the time of writing, this is most commonly "http://json-schema.org/draft-04/schema#"
See https://spacetelescope.github.io/understanding-json-schema/reference/schema.html for some discussion about the $schema keyword.

Related

Generate Angular2 forms from Swagger API specification

I'm looking for a way to generate a set of Angular2 form templates from a Swagger API definition file. I want a result that will allow me to test my POST/PUT requests, and even use it in my app.
After some research I found this Angular2 form library that takes a JSON schema as input: https://github.com/makinacorpus/angular2-schema-form
So if you know of a Swagger -> JSON Schema converter that will work too.
Cheers!
So if you know of a Swagger -> JSON Schema converter that will work
too.
Swagger 2.0 supports a subset of JSON schema draft 4. This is what swagger's Schema object is. From the docs:
The following properties are taken directly from the JSON Schema
definition and follow the same specifications:
$ref - As a JSON Reference
format (See Data Type Formats for further details)
title
description (GFM syntax can be used for rich text representation)
default (Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object)
multipleOf
...
The following properties are taken from the JSON Schema definition but
their definitions were adjusted to the Swagger Specification.
items
allOf
properties
additionalProperties
It should be a fairly simple exercise to manually extract the schema from your swagger, but I don't know of any automated tool to do this. I think the fact some of the JSON schema properties have been modified by swagger may make auto conversion problematic in certain circumstances.

yaml validation against pojo/bean

I have a schema defined in yaml format. At application startup, I just need to verify that this schema has not been changed. So for that, in code I need to write a bean and validate that schema against that bean. Is this possible? It may sound strange because usually payloads are validated against schema, but I need to validate schema against a bean. Any JAVA based solution?
I was looking at Jackson-module-jsonSchema but it generates Schema from a bean, not validate a bean against a schema AND its json not yaml.
P.S. I can convert yaml to json if need be (if an api is available to do this in json)

Has anyone heard of a JSON schema that generates a Json schema?

I'm looking for a Json Schema that generates a Json schema. that sounds a little confusing but if I can try to simplify it I'm looking for a Json schema that out lines the rules to make a Json schema and outputs them.
You're looking for the meta-schemas. From JSONSchema:
Meta-schemas
The meta-schemas are the schemas which define the JSON Schema and Hyper-> Schema formats.
Core/Validation Meta-Schema: Used for schemas written for pure validation.
Hyper Meta-Schema: Used for schemas written for validation and hyper-linking.
Taken from: http://json-schema.org/documentation.html

How to generate simple JSON object from json schema?

is there any website or chrome-extension that generates sample JSON object from JSON schema?
Thank you very much.
Yes there are: json schema faker
More information you can find here: json schema implementations

How do I validate JSON against XML Schema (XSD) or RelaxNG?

I'm defining the structure of JSON documents. I'd like to know if how to validate the JSON documents against existing XSD, RelaxNG schemas or another standard schema language schema. I know of Jsonix, but I don't see that it uses the regular expressions from XSD or RelaxNG for validation against JSON schema (and I don't think that JSON schema is standardized).
Clarification: We already have existing XML and XSD. We can always go back to XML for validation, but it would be cool if we could validate the JSON directly, and would give us more confidence when we want to use the JSON and not XML.
Update: Here is the specification in question: http://www.web3d.org/specifications/x3d-3.4.xsd note that it doesn't have text nodes in the XML documents.
Preliminary answer (still a work in progress, but you can contribute):
If you want to convert XML schema to JSON schema, try downloading: XSD2OWL stylesheet which converts XML Schema to OWL. I converted my schema to owl like this:
$ xmlsh
$ xslt -f xsd2owl.xsl -cf file.xsd > file.owl
$ exit
Then download owl2jsonschema.js ** NO LICENSE ** and modify it until it until the demo works. The output will be in demo/OUTPUT/schema folder/*.json as separate JSON files.
XSD and RelaxNG are defined against XML, not JSON.
For JSON, see JSON Schema, but realize that it has nowhere near the adoption of XSD, and the latest draft of the specification expired August 3, 2013, casting doubts on the future of the effort.
Update
How do I validate JSON against XML Schema (XSD) or RelaxNG?
You don't.
The question is not "Can I?" but "How?" Say I have total control over
the JSON document.
When the answer to "Can I?" is "No" the question of how does not apply.
Clarification: We already have existing XML and XSD. We can always go
back to XML for validation, but it would be cool if we could validate
the JSON directly, and would give us more confidence when we want to
use the JSON and not XML.
You can validate the JSON directly against a JSON Schema, but not against an XSD. There are no tools that can do that; the standards are substantially different. The need to define standard vocabularies and grammars that is served by XSD and RelaxNG against XML was intended to be met by JSON Schema against JSON.
You're looking for "confidence when we want to use the JSON and not XML" in the wrong place. See reasons for choosing XML vs JSON instead.
As you're probably already aware of the information I'm about to post, this is just for reference.
Jsonix Schema Compiler supports generation of JSON Schema based on the XML Schema.
So with this you can convert you XML Schema into JSON Schema and validate your JSON against this JSON Schema using AJV.
This is still an experimental feature but that's the direction.