javascriptarraysjsonvalidationjsonlint

JSON format failing on JSONLint


I'm writing some functions that construct what should be a properly formatted JSON string which I can then parse into a JSON object.

My object is failing on JSONLint with the following error:

syntax error, unexpected TINVALID at line 2

[
    SERVER: {
        ip = 10.10.10.1,
        port = 8100
    },
    TYPES: [
        ssh,
        shht
    ]
]

I assumed that this would give me an array of JavaScript objects.

Even if I did this instead (object instead of array):

{
    SERVER: {
        ip = 10.10.10.1,
        port = 8100
    },
    TYPES: [
        ssh,
        shht
    ]
}

It doesn't work and I get the same error:

I assume that with the object, I would be able to access some data like so:

var serverIP = myObject.SERVER.ip;

That's certainly what I'd like to do.

Many thanks in advance,

Joe


Solution

  • your mixing json object with javascript arrays

    this is json format

    {
        "item":"value",
        "item2":"value"
    }
    

    and this would be a JavaScript array

    [
        "apple",
        "orange"
    ]
    

    os I think this is what you are looking for

    {
        "SERVER": {
            "ip": "10.10.10.1",
            "port": 8100
        },
        "TYPES": [
            "ssh",
            "shht"
        ]
    };