-2

How to retrieve value from json using webload javascript

Message: keys value is : {"_Success": 1, "Criteria": "1234", "SearchAndSelect":  [ {"DateOfBirth": 
"15/02/1962","EmpNo": "123456","LastName": "John", "FirstName": "Smith", "Reference": "1234", "Keys": 
"5eac0bbd-82d7-4959-8496-2cdb13dea292" } ]  }

I want to retrieve the value of Keys

"Keys": "5eac0bbd-82d7-4959-8496-2cdb13dea292"

Suma
  • 103
  • 2
  • 14
  • Firstly the JSON needs parsing `JSON.parse(JSONText)`. Then you can use JavaScript dot/square bracket notation to access the property. – evolutionxbox Feb 23 '21 at 12:02
  • Does this answer your question? [Parse JSON in JavaScript?](https://stackoverflow.com/questions/4935632/parse-json-in-javascript) – evolutionxbox Feb 23 '21 at 12:10

4 Answers4

1
var jsonParsed = JSON.parse(json);

var keys = jsonParsed.SearchAndSelect[0].Keys;

console.log(keys); // "5eac0bbd-82d7-4959-8496-2cdb13dea292"
Ran Turner
  • 14,906
  • 5
  • 47
  • 53
0

Use :

JSON.parse(`{"_Success": 1, "Criteria": "1234", "SearchAndSelect":  [ {"DateOfBirth": 
"15/02/1962","EmpNo": "123456","LastName": "John", "FirstName": "Smith", "Reference": "1234", "Keys": 
"5eac0bbd-82d7-4959-8496-2cdb13dea292" } ]  }`)
0

SearchAndSelect is the Key of the JSON which you should search in. It is a List of JSONS so in case you are using javascript you would do something like this

let data = JSON.parse(result)

for(let element of data.SearchAndSelect){
    console.log(element.Keys)
}

This handles in case there are multiple values in SearchAndSelect Array

Srinjoy Choudhury
  • 622
  • 1
  • 4
  • 19
0

var data = {"_Success": 1, "Criteria": "1234", "SearchAndSelect":  [ {"DateOfBirth": 
        "15/02/1962","EmpNo": "123456","LastName": "John", "FirstName": "Smith", "Reference": "1234", "Keys": 
        "5eac0bbd-82d7-4959-8496-2cdb13dea292" } ]  };

    for (const property of data['SearchAndSelect']) {
          console.log(property['Keys']);
    }
Ravi Ashara
  • 1,177
  • 7
  • 16