How to fetch the JSON elements value - any function available OOB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2016 06:37 AM
By using the below code, i am able to get the exact JSON request body which is getting passed from another application
var json = new JSON().encode(request.body.data)
{
"code":200,
"params":{},
"data":{
"element1":" 111",
"element2":"234",
"element3":"567",
"element4":"2015-01-18",
}
}
I need to fetch one of the elements value (element2) from within this JSON request body and further use that for updating a record's field.
How can i fetch this , is there any function available OOB. In JSON Script include, i cannot see any function to accept a key .which returns a value.
I even tried using dot walking (like json.data.element1, also json.element1,) but it gives me undefined error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2016 04:52 AM
Hi Sumeet,
You are correct hinting that, no json encoder or decoder is required, basically the object which is returning in the RestAPIrequest parameter could be used as below.
Got the solution here,
var req= request.body.data; -- returns [object Object]
gs.log(req.data.element1) -- returns "111"