mrtonyb
mrtonyb

Reputation: 615

Validate JSON Multidimensional

Is this written correctly? Is there a better way to write it? This is similar to the real data I am working with and I want to ensure that I'm nesting the objects or arrays properly in the JSON file.

var data = [
    {
        "department": "IT",
        "jobs": {
            "title": {
                "programmer": [ 
                    { "skill": "PHP"  },
                    { "skill": "Ruby" }
                ],
                "systems analyst": [ 
                    { "skill": "requirements gathering" },
                    { "skill": "problem solving" }
                ] 
            },
        }
    }               

Upvotes: 0

Views: 90

Answers (2)

classicjonesynz
classicjonesynz

Reputation: 4042

I think there is some major accessibility issues in your "title" section of your literal object.

{
    "department": "IT",
    "jobs": [
        {
            "title": "programmer",
            "skils": [
                {
                    "skill": "Ruby"
                },
                {
                    "skill": "PHP"
                }
            ]
        },
        {
            "title": "systems analysis",
            "skils": [
                {
                    "skill": "problem solving"
                }
            ]
        }
    ]
}

Is much easier to loop over;

var MyList = jQuery('<ul></ul>');
for(var x = 0; x < data.jobs; x++) {
    var new_job = data.jobs[x];
    MyList.append('<li>' + new_job.title + '</li>');
    // and so fourth ...
}

Upvotes: 0

Netorica
Netorica

Reputation: 19347

try to validate it with JSON Lint

http://jsonlint.com/

Upvotes: 2

Related Questions