CoreeLip
CoreeLip

Reputation: 1

Reading a JSON file with Java script

This is the format of my JSON file. I am fairly new to javascript and want to be able to read each key and pull each augment. I am just confused on where to start.

AuthServer.Web": {
    "stuff": {
        "evenmore stuff": {
            "evermore": "3d91f44c-2453-489c-bb61-dd42df803179",
            "anything": "6cc7b9d0-423c-471a-be77-7c95d432e50d",
            "things": "https://auth-drip.coree.com",
            "environment": "dev",
            "migrate": "1"
},

Upvotes: 0

Views: 46

Answers (1)

DanGrim83
DanGrim83

Reputation: 17

https://jsonformatter.curiousconcept.com/

This site is a json validator. You can plug your JSON string in and it will tell you if it is valid, and if not what is wrong.

In javascript you can use var myData = JSON.parse(yourData) to get your JSON into an object. After that depending on how you build your JSON you can loop through it using the variable names you assign.

Just to get a rough idea based on what I think you were trying to do, you can do something like this.

for(var x=0; x<myData.stuff.length; x++){
    for(var y=0; y<myData.stuff[x].length; y++){
        for(var z=0; z<myData.stuff[x].evenmoreStuff[y].length; z++){
            alert(myData.stuff[x].evenmoreStuff[y].anything.toString()
        }
    }
}

Upvotes: 1

Related Questions