1

I'm trying to parse through the following JSON file using Javascript. Can somebody help me with how to retrieve the data from this kind of JSON structure?

{
    "game_schedule": [
            {
                "day1":{
                    "date": "05/21/2016",
                    "time": ["09:06 am", "12:00 pm", "08:05 pm"],
                    "game": [
                        "SF Giants vs NY Mets",
                        "LA Dodgers vs SD Padres",
                        "SF Giants vs SD Padres"
                        ]
                },
                "day2":{
                    "date": "05/22/2016",
                    "time": ["09:06 am", "04:09 pm"],
                    "game": [
                        "LA Dodgers vs SF Gaints",
                        "LA Dodgers vs NY Mets"
                        ]

            }
        }
    ]  
}
9
  • json is javascript. Did you did the json from server? In that case what have gotten is probably a string? Show your parsing code. Commented May 1, 2016 at 1:57
  • 1
    When a JSON file is parsed (with JSON.parse), it becomes a JavaScript dictionary and can be accessed in the normal ways. Commented May 1, 2016 at 1:58
  • 1
    I'm not entirely sure what you're asking? What have you tried? Commented May 1, 2016 at 1:58
  • @SureshKoya - JSON is not Javascript. JSON is a string representation of data that happens to look a lot like JavaScript code. Commented May 1, 2016 at 1:59
  • @nnnnn - json is Javascript Object Notation Commented May 1, 2016 at 2:01

1 Answer 1

1
var obj = JSON.parse( json_string );

// obj['game_schedule'][0]['day1']['date'] == '05/21/2016'
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply. Can you please tell how to do it if JSON string is in a file?
You'd need to specify how the file is stored. Where it's located. How it's accessed etc. Try googling that bit first. It might be a separate question for you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.