Searching JSON Field for Key-Value Pairs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2024 05:47 AM
Hi Team,
I have a table with a JSON field, and I need to search for a specific key-value pair within that JSON data. For example, given the JSON data:
{"sys_id": "1", "name": "Hello world", "class": "Business application"}, {"sys_id": "2", "name": "Service Now", "class": "world"} I want to perform a query to find entries where the "name" field contains the value "world." How can I achieve this?
I want to search in the "Json data" field in the below attached screenshot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2024 05:51 AM - edited ‎09-17-2024 05:58 AM
if it is a array of object
var sample = [ {"sys_id": "1", "name": "Hello world", "class": "Business application"}, {"sys_id": "2", "name": "Service Now", "class": "world"} ]
var jsonData = JSON.parse(sample);
for (var i = 0; i < jsonData.length; i++)
{
var item = jsonData[i];
if (item.name && item.name.includes("world"))
{
gs.info("Match found: " + JSON.stringify(item));
}
Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2024 06:08 AM
No if you check the screenshot attached Json data is the field in the "sn_grc_indicator_supporting_data" table. I want to search on that field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2024 06:19 AM
Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution