'Combinability of JSON strings into a valid JSON string
Is it possible guaranty that the string generated in the following way always results in a valid JSON?
I use for example the following template with the placeholder &someanotherjsonstring&
{
"key1": "value1",
"key2": "value2",
"data": &someanotherjsonstring&
}
So, if someotherjsonstring
is {"a": 1}
the resulting string is a valid JSON string:
{
"key1": "value1",
"key2": "value2",
"data": { "a":1 }
}
According to my understanding of the JSON syntax grammar [1] the resulting string will always be a valid JSON, because:
- A valid JSON string is either array or object.
- A value of a key:value pair can be array or object (among other data types).
Is my understanding of the JSON grammar correct and I can assume the expanded template is always a valid JSON, independently of the placeholder value, given it is a valid JSON?
References
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|