Michelle
Michelle

Reputation: 89

Error in Json syntax

I'm writing a json syntax and when I validate it I keep getting the error,

Parse error on line 6:
..."Dublin 1",        {            "produ
----------------------^
Expecting 'STRING'

I can't figure out what the error means.

Here's my code

{"invoice":
{"number":"1001",
 "date":"21/02/2010",
 "customer":"Joe Bloggs",
 "address":"Dublin 1",
{"product details":
        [
          "name1":"Table",
          "quantity1":"1",
          "amount1":"250"
         }
         {
          "name2":"Chair",
          "quantity2":"6",
          "amount2":"200"
         }
        ]
}
}}

Upvotes: 0

Views: 110

Answers (2)

Roman Mik
Roman Mik

Reputation: 3279

I strongly suggest finding a good Json Editor. If you work with C#, Java or other typed languages consider using libraries that allow you to generate Json. The point is, if you manually assemble JSON, you will have typos, unless you have an eye for details :)

{
   "invoice":
      {
         "number":"1001",
         "date":"21/02/2010",
         "customer":"Joe Bloggs",
         "address":"Dublin 1",
         "product details":
         [
            {
               "name1":"Table",
               "quantity1":"1",
               "amount1":"250"
            },
            {
               "name2":"Chair",
               "quantity2":"6",
               "amount2":"200"
            }
        ]
    }

}

Upvotes: 0

Mike Robinet
Mike Robinet

Reputation: 843

JSON is filled with key-value pairs, so I see at least three problems.

1) The "product details" object needs a key. Maybe "product details" was meant to be the key?

2) You are missing the start { for the first object in the product details array value.

3) You are missing a comma separating product detail objects.

Here is some valid json that might be what you are intending:

{
    "invoice": {
        "number":"1001",
        "date":"21/02/2010",
        "customer":"Joe Bloggs",
        "address":"Dublin 1",
        "product details": [
            {            
                "name1":"Table",
                "quantity1":"1",
                "amount1":"250"
            },
            {
                "name2":"Chair",
                "quantity2":"6",
                "amount2":"200"
            }
        ]
    }
}

Use a JSON validator such as this one to validate your JSON: http://jsonformatter.curiousconcept.com/

Upvotes: 2

Related Questions