user3353015
user3353015

Reputation: 11

Json array formatting

I am having an issue with this JSON file. I cannot seem to find out what I did wrong. I was told my formatting was incorrect by a friend but cannot seem to find out how I went wrong.

Would anybody be able to point out the flaw in my formatting and explain so I can prevent this from happening on further projects?

http://pastebin.com/nzTrPvMd

This is the pastebin file

Upvotes: 0

Views: 37

Answers (2)

Thanatos
Thanatos

Reputation: 44246

The mapping in the middle of the file is weird:

{
        "Username":"CENSORED", "CENSORED",

A key (like "Username") can only have one value. You appear to be trying to store two here. Mappings look like this:

{
    "key": "a value",
    "another key": "another value",
    "number of things": 4,
}

Keys must be strings, but values can be any JSON type. You can, for example, have a key point to a list:

"Username": ["CENSORED", "CENSORED"]

Or a mapping with descriptive keys, if a list isn't appropriate:

"Username": {
    "FirstName": "CENSORED",
    "LastName": "CENSORED"
}

Upvotes: 1

Alberto Fecchi
Alberto Fecchi

Reputation: 3396

in JSON, square brackets [] indicates an array as a list. A JSON list never contains associative keys, here valid examples:

["first", "second", "third"]
[{"id":"1"}, {"id", "2"}]

Braces indicate an array as an object that could contain nothing or N pair of values ("key":"value"). an example:

{"id":"1"}
{"name":"john", "age":"12"}
{} (empty object)

Follow this easy instruction and you'll make valid JSON every time

Upvotes: 0

Related Questions