Monday, May 14, 2018

JSON note

https://spacetelescope.github.io/understanding-json-schema/
The file type for JSON files is ".json"
The MIME type for JSON text is "application/json"

JSON syntax is derived from JavaScript object notation syntax:
Data is in name/value pairs
Data is separated by commas
Curly braces hold objects
Square brackets hold arrays

In JSON, values must be one of the following data types:

a string
a number
an object (JSON object)
an array
a boolean
null

JavaScript does not have separate types for integer and floating-point.
JSON values cannot be one of the following data types:

a function
a date
undefined

Numbers in JSON must be an integer or a floating point.
{ "age":30 }
Values in JSON can be true/false.
{ "sale":true }
Values in JSON can be null.
{ "middlename":null }

string format:
https://spacetelescope.github.io/understanding-json-schema/reference/string.html

There are two numeric types in JSON Schema: integer and number. They share the same validation keywords.
minimum, maximum

can use the below to indicate it's a json schema instead of normal json doc file:
"$schema": "http://json-schema.org/draft-04/schema#",


It is also best practice to include an id property as a unique identifier for each schema. For now, just set it to a URL at a domain you control, for example:
{ "id": "http://yourdomain.com/schemas/myschema.json" }

Json to Json schema: https://www.liquid-technologies.com/online-json-to-schema-converter
Json to Java class: http://pojo.sodhanalibrary.com

to adjust the field order, can use annotation @JsonPropertyOrder
to add array name, may need put the array/list to a map