2

Is this valid JSON?

{
    "a" : [
      "x",
      "x"
    ]
}

http://jsonlint.com/ says yes.

http://www.json.org/ doesn't say anything about it being forbidden, but does say:

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.

  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

"An ordered list of values" suggests duplicates are therefore valid. Is this correct? Is there anything more explicit? Are there any JSON implementation which don't allow duplicate values?

(Here's the related question about duplicate keys.)

1 Answer 1

2

That is valid JSON. What is not allowed is having duplicate keys, such as:

{
    "a": 1,
    "a": 2
}

Also, by "ordered" I believe it refers to the fact that values have a predefined, well established order, not that they are sorted in any way :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.