Reputation: 823
Note: this is a NodeJs app
I have the following JSON object that stores questions and answers:
{
"id": "SOME_GUID",
"questions": {
"page-1": {
// ... JSON schema for page 1.
},
"page-2": {
// ... JSON schema for page 2.
}
},
"answers": {
"page-1": {
"page-1-question-1": "something"
},
"page-2": {
"page-2-question-1": true,
"page-2-question-2": "foo"
},
}
}
Is there a benefit of representing the data in a specific way over another? I would naturally opt for a simple key/value pair notation (shown below) as it seems to fit the bill here. But I have seen the "array notation" (shown below) in the wild (in projects written in Java)
key/value pair notation (what I would naturally use):
{
"meta": {
"createdData": "some date",
"modifiedData": "some date",
"referenceNumber": "some reference number",
"type": "some type code"
}
}
or
"array" notation
{
"meta": [
{
"key": "createdDate",
"value": "some date"
},
{
"key": "modifiedData",
"value": "some date"
},
{
"key": "referenceNumber",
"value": "some reference number"
},
{
"key": "type",
"value": "some type code"
},
]
}
Upvotes: 4
Views: 18193
Reputation: 116919
I would naturally opt for a simple key/value pair notation
In that case, you might wish to consider the JSON Extended Structural Schema language (JESS) and associated tools, which include a schema inference engine and verification checker.
The idea basically is to use the inference engine to get a draft schema that exactly mirrors the input; modify it as needed, e.g. to to override some inferences or to define more complex constraints; and then use the derived schema with the verification checker.
The inference engine requires valid JSON as input, so I've tweaked the sample given, as shown below. Given this as input, the schema inference engine produces:
{
"id": "string",
"questions": {
"page-1": {
"page1 schema": {}
},
"page-2": {
"page2 schema": {}
}
},
"answers": {
"page-1": {
"page-1-question-1": "string"
},
"page-2": {
"page-2-question-1": "boolean",
"page-2-question-2": "string"
}
}
}
The inference engine and checker currently require jq to run. There is a node.js wrapper for jq (e.g. yarn add node-jq
), which might help.
JESS is relatively new. The JESS Language is stable but there are some finer points that are subject to change.
I am the author of JESS.
{
"id": "SOME_GUID",
"questions": {
"page-1": {
"page1 schema": {}
},
"page-2": {
"page2 schema": {}
}
},
"answers": {
"page-1": {
"page-1-question-1": "something"
},
"page-2": {
"page-2-question-1": true,
"page-2-question-2": "foo"
}
}
}
Upvotes: 1
Reputation: 1
{
"characteristics": {
"organism": {
"name": "",
"accession": "",
"ref": ""
},
"organism_variant": {
"name": "",
"accession": "",
"ref": ""
},
"organism_part": {
"name": "",
"accession": "",
"ref": ""
}
}
}
Reference Link : https://2isa.readthedocs.io/en/latest/other/json-metadata.html
Upvotes: 0