1

Possible Duplicate:
I have a nested data structure / JSON, how can I access a specific value?

How to parse this JSON in jQuery or JSON?

Example:

{
  "Travel": {
    "Transport_type": "Road",
    "Options": {
      "Destination": "Delhi",
      "BusType": "Volvo",
      "Time": "Night",
    },
    "Carrier": {
      "Private": {
        "Service_Provider": "Sharma",
        "Features": {
          "Seats": "PushBack",
          "Indoor Pantry": "Available",
        }
      },
    }
  }
}

I'm not able to use the json.parse function to get the results.

Community
  • 1
  • 1
WonderBoy
  • 279
  • 1
  • 3
  • 7
  • 4
    The function is `JSON.parse`, not `json.parse`. And unless there are more items in your actual JSON, trailing commas (like in `"Time": "Night",`) are invalid. Check your JSON with http://jsonlint.org/. If you build your JSON "by hand": don't! Most languages have functions to convert native data structures into JSON. Use those. It does not matter "how complex" the JSON is as long as it is valid. If you provide more information, we can help you better. But as it looks now, you simply have a syntax error, and thus this question is "too localized". – Felix Kling Jan 22 '13 at 11:22
  • Yes , actually i have built the JSON by hand , since i had to give an example. Actually my original JSON is validated in jsonlint. Im not able to find a generic means to parse it since the elements are not consistent. – WonderBoy Jan 22 '13 at 11:29
  • So... `JSON.parse` *does* work (i.e. you can parse the JSON) but you don't know how to access the object properties? – Felix Kling Jan 22 '13 at 11:30
  • yes , im pretty new to JS and i want to know how to parse it. – WonderBoy Jan 22 '13 at 11:31
  • Thanks for the Quick Reply !!! Appreciate a lot ... – WonderBoy Jan 22 '13 at 11:37
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/23144/discussion-between-user659982-and-felix-kling) – WonderBoy Jan 22 '13 at 11:38

1 Answers1

1

As long as you have a valid JSON string, you can parse using javascript function JSON.parse() or using jQuery function - jQuery.parseJSON().

Please validate your JSON string first.

Sudip Kafle
  • 4,286
  • 5
  • 36
  • 49