I am working on a research project that requires storing a large amount of external data. I have settled on the JSON format, which I have never used, as a storage format. All I really need to store is a large array of data however every example of JSON I can find that has an array in it is nested inside of an object. for example:
{ "NumberList" : {
"array" : [ 1, 2, 3, 4, 5, 6] }}
Is it possible to have only an array? Such as:
"array" : [1,2,3,4,5,6]
Without an opening and closing bracket or a surrounding object?
The accepted answer is wrong. JSON can start and end with an array. The official JSON document says
JSON is built on two structures:
- A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
- An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
You can also see it through JSON validator.
In a nutshell, while you still cannot do "array" : [1,2,3,4,5,6]
, you can store it like [1,2,3,4,5,6]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With