How to maintain the key value structure when parsing JSON file in Javascipt

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to maintain the key value structure when parsing JSON file in Javascipt



I have a JSON file that I want to parse into a JavaScript object with the following structure:


"sessions": [
"laps": [
"records": [
session 1 lap 1 record 1,
session 1 lap 1 record 2,
...
]
]
]



I parse it using the JQuery getJSON method, however the object I get looks like this:


sessions: [array of sessions],
laps: [array of laps],
records: [array of records]



In the original JSON file, records are one of the key-value pairs of laps, and laps are one of the key-value pairs of sessions. However the JavaScript object I get does not reflect this in its properties. I tried to parse the file using the JavaScript built-in function JSON.parse() but the same thing happened.



Why does this happen and is there any way to maintain the structure after parsing the JSON file to a JavaScript object?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS