Are JSON schemas necessary for defining the structure of a JSON? -
Are JSON schemas necessary for defining the structure of a JSON? -
i asking because see current json schema draft (http://json-schema.org/) proposes have schema of json in next way:
for json :
{ "a":"abc" "b": 123 }
the schema proposed in draft like
{ "type":"object" "properties":{ "a": {"type":"string"} "b": {"type":"integer"} } }
my question here json not define structure? separate schema necessary?
the schema proposed draft validates json have above construction , json of format
{ "a":"string" "b": 1 (or number) }
so need of separate schema json. can utilize json define construction also.
ps. know can specify restrictions on values json can take through schemas proposed in draft, point of view of defining construction of json, proposed schemas necessary?
the json not define structure. example, write:
{ "a": "string", "b": "another string" }
that's valid json - it's "differently structured" json, because "b"
string. api might take json particular structure, although it's valid json, it's not shape need.
now, need json schema define construction of json data? no. instead say:
the value must object. must have 2 properties:
"a"
- must string "b"
- must integer a programmer understand easily, no squiggly brackets or anything.
however, there advantages having machine-readable description of format, because lets automate various things (e.g. testing, generating documentation, generating code/classes, etc.)
edit: pointed out in comments, can take type info illustration data, , utilize model other data. in case, you're using illustration info super-basic schema.
for simple constraints (basic type), works. however, how "b"
has integer instead of float? how "b"
must > 0? how "a"
must not empty string (""
)?
there indeed tools generate basic json schema illustration info - however, resulting schema requires bit of tweaking describe format (e.g. min/max, required/optional properties, etc.).
json schema jsonschema
Comments
Post a Comment