Minimal JSON data structure containing a value [duplicate] - json

This question already has answers here:
What is the minimum valid JSON?
(8 answers)
Closed 6 years ago.
Looking at json spec, I'm not sure whether a value is permitted to stand alone, or is only permitted as part of object or array structure.
This is valid JSON:
[123]
But is this valid JSON:
123

Per ECMA-404, The JSON Data Interchange Standard (pdf), which is linked from the JSON.org page you linked:
A JSON text is a sequence of tokens formed from Unicode code points that conforms to the JSON value grammar.
And:
A JSON value can be an object, array, number, string, true, false, or null.
As such, the value 123 is valid JSON, representing an integer.

A value is permitted to stand alone.
The rule has been changed a few years ago.

Related

How to set JSON object value as referred by another key:value pair in the same file [duplicate]

This question already has an answer here:
Can I refer to one json object in another object in the same json file?
(1 answer)
Closed 2 years ago.
In a JSON file, how to set object value that is referred by another key : value pair in the same JSON file, (not in JAVA / any programming language).
"FRUIT_A":"Watermelon",
"FRUIT_B":"Mango",
"FRUIT_C":"Apple",
"FRUIT_D":"Grape",
// How to set the value with reference of another key.value.
"BIGGEST_FRUIT": ${FRUIT_A}, // <-- just a reference to explain what I want to achieve.
"SMALLEST_FRUIT": ${FRUIT_D}, // <-- another ref, don't know what notation.
Not sure, if it is possible to do within JSON file itself.
From above example, I basically want to set the values of keys as below:
"BIGGEST_FRUIT": "Watermelon",
"SMALLEST_FRUIT": "Grape",
JSON is a simple text based file which stores data in key value format. If you want to refer value of another key then there has to be some resolver which will resolve the reference and provide you the expected value.
If you would like to know more on Please checkout this link

Why ! after String in graphql? [duplicate]

This question already has answers here:
What is an exclamation point in GraphQL?
(3 answers)
Closed 2 years ago.
What is the purpose of appending ! after String param in graphql methods.
query method($param: String!)
This modifier means that the type cannot be null.
String! means that the field is non-nullable, meaning that the GraphQL service promises to always give you a value when you query this field. In the type language, we'll represent those with an exclamation mark
The Non-Null type modifier can also be used when defining arguments for a field, which will cause the GraphQL server to return a validation error if a null value is passed as that argument, whether in the GraphQL string or in the variables.
https://graphql.org/learn/schema/#type-system
What is an exclamation point in GraphQL?

Mongodb/Mongo Query: How do I deserialize nested JSON stored in a string field? [duplicate]

This question already has answers here:
MongoDB: How to query over a json string?
(1 answer)
Using stored JavaScript functions in the Aggregation pipeline, MapReduce or runCommand
(1 answer)
Closed 3 years ago.
In the context of metabase:
I am applying the following one-liner query to extract a particular field from a collection of mongodb documents:
[{"$project":{"myName":"$field1.field2" }},
{"$match":{"_id":{"$eq":"blah"}}} ]
myName is a string field that is in fact a serialized JSON object.
How can I adapt the pipeline above, perhaps using JSON.parse(), to pull out fields nested further down the JSON hierarchy?
Part II: How would I add a final step to extract some of those deeply nested fields? The situation is further complicated because the document structure is not consistent between documents...
Thanks!

Missing data when Marshalling map to JSON [duplicate]

This question already has answers here:
JSON and dealing with unexported fields
(2 answers)
Printing Empty Json as a result [duplicate]
(1 answer)
(un)marshalling json golang not working
(3 answers)
json.Marshal(struct) returns "{}"
(3 answers)
Closed 10 months ago.
I'm trying to marshal to JSON a struct Foo that has a Values map[string]CellValue property where CellValue is another struct. For some reason, the resultant JSON does not contain the data held in the CellValue struct even though all the keys in the Values map are present.
Here's a simple playground repro of the issue.
I'm new to Go, can anyone spot the problem here?
The fields of CellValue are unexported (start with a lowercase character). Per the documentation (emphasis mine), "Each exported struct field becomes a member of the object" - meaning unexported values are ignored when marshaling or unmarshaling.

Is a single string value considered valid JSON? [duplicate]

This question already has answers here:
What is the minimum valid JSON?
(8 answers)
Closed 7 years ago.
Do you consider the JSON web response:
"A serialization error occurred"
to be valid or not?
Some validators accept it while others don't.
As for new JSON RFC, json, containing only single value is pretty valid.
A JSON text is a serialized value. Note that certain previous specifications of JSON constrained a JSON text to be an object or an array.
There's a change of heart on this between RFC4627 and RFC7159:
RFC4627:
A JSON text is a serialized object or array.
JSON-text = object / array
RFC7159:
A JSON text is a serialized value. Note that certain previous
specifications of JSON constrained a JSON text to be an object or an
array. Implementations that generate only objects or arrays where a
JSON text is called for will be interoperable in the sense that all
implementations will accept these as conforming JSON texts.
JSON-text = ws value ws
No philosophical or practical justification is provided for this change of heart. The earlier version probably makes more sense as it consistently dictates that both a singe list element and a single map element (a pair or tuple) be contained. The second version allows only a single list element to be uncontained.
According to the grammar exposed in http://www.json.org/ (which references the Standard ECMA-262 3rd Edition - December 1999 par.5.1.5 The JSON Grammar) it's wrong:
The initial element must be:
and then a value can be a string:
From RFC4627:
A JSON text is a serialized object or array.
JSON-text = object / array
IE, the root element has to be an object or array, and can't be a string value by itself.
I don't care if some validator accepts it. It's wrong. It's a question of good practice, Json format must be {"key": "value", .....}. If you consider that text Json, can work, but for the rest of programmer it's not a serious Json. If you use only that text, then you don't need Json.