How to get a specific value from json

2.1k Views Asked by At

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"

4

There are 4 best solutions below

0
On BEST ANSWER
var jsonParsed = JSON.parse(json);

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

console.log(keys); // "5eac0bbd-82d7-4959-8496-2cdb13dea292"
1
On

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
On

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

0
On

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']);
    }