0

HI I am trying to create a JSON file in which I want to store some data for different files. The problem is I cannot figure the correct syntax. Here is what I have so far:

var object = {
    "id-1" :[
                {
                    "type":"Corporate Website",
                    "tech":"HTML" ,"CSS" , "Javascript/jQuery"

                }
            ], 
    "id-2" :[

             ]
}

I seem to be getting an error at "tech".If that is not corect how can I enumarate multiple elements?I am sorry for the noob question I have been using javascript for a short period of time and I am still very confused with the language.

2
  • 6
    Note that what you have is a JavaScript object literal, not JSON. JSON is just a text format that happens to be a subset of JavaScript. Commented Jul 9, 2012 at 18:33
  • FYI if you have trouble with javascript syntax check out jslint.com and with JSON: jsonlint.com Commented Jul 9, 2012 at 19:03

2 Answers 2

7
{
"id-1": [
    {
        "type": "Corporate Website",
        "tech": [
            "HTML",
            "CSS",
            "Javascript/jQuery"
        ]
    }
],
"id-2": []
}

Note the array like syntax for "tech".

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

1 Comment

If they're not necessary, you could also lose the additional square brackets around the value corresponding to the key "id-1". These turn it into an array of size one. They are unnecessary in the example shown, unless you need more values assigned to some ids.
5

Tech should be an array (enclosed in square brackets):

"tech": ["HTML", "CSS", "Javascript/jQuery"]

Source:

An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).

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.