I am trying to get the value from statusAprovacao
, that is "Pre aprovado", but when I use the script var list = json.prop("statusAprovacao");
the result is empty. What is the right way to query this value using JavaScript?
The script I tried:
var json = S(response);
var list = json.prop("statusAprovacao");
the result:
SPIN/JACKSON-JSON-01004 Unable to find 'statusAprovacao'/
Json Script:
[{"statusAprovacao":{"type":"String","value":"Pre aprovado","valueInfo":{}},"analisar":{"type":"Boolean","value":true,"valueInfo":{}}}]
I am trying to get the value from statusAprovacao
, that is "Pre aprovado", but when I use the script var list = json.prop("statusAprovacao");
the result is empty. What is the right way to query this value using JavaScript?
The script I tried:
var json = S(response);
var list = json.prop("statusAprovacao");
the result:
SPIN/JACKSON-JSON-01004 Unable to find 'statusAprovacao'/
Json Script:
[{"statusAprovacao":{"type":"String","value":"Pre aprovado","valueInfo":{}},"analisar":{"type":"Boolean","value":true,"valueInfo":{}}}]
Share
Improve this question
edited Jun 12, 2021 at 16:33
Hendy Irawan
21.5k12 gold badges110 silver badges116 bronze badges
asked Apr 19, 2018 at 16:02
Rudson RodriguesRudson Rodrigues
3455 silver badges25 bronze badges
5
-
1
Ummm
var list = json[0]["statusAprovacao"];
– Ele Commented Apr 19, 2018 at 16:03 -
4
What is this:
S(response)
? What lib are you using to parse JSON? Why not justJSON.parse
? – Luan Nico Commented Apr 19, 2018 at 16:06 -
SPIN/JACKSON-JSON-01004
I'm afraid, are you trying to use third-party libraries to parse JSON in the language it's native to? Just in case, JSON means JavaScript Object Notation... – Aaron Commented Apr 19, 2018 at 16:07 - S(response) is the standard used at the Camunda BPM, that I am using to make this query. – Rudson Rodrigues Commented Apr 19, 2018 at 16:13
-
1
@MadhukarHebbar To be fair to the downvoters, the asker did not mention Camunda at all in the title nor in question body. So it would be confusing. The only hint was
camunda
in the tags. So I fixed the title, to get better SEO too, as the answers are fortunately helpful. – Hendy Irawan Commented Jun 12, 2021 at 16:34
3 Answers
Reset to default 3Camunda Spin is a wrapper around Jackson that Camunda provides for JSON (and XML) processing. While I find it very helpful for processing JSON in Java, I prefer processing JSON natively within JavaScript (in Nashorn in this case). Your mileage may vary. :) Here's an example illustrating how to process the JSON natively in Nashorn, assuming response
is stringified JSON:
var responseObj = JSON.parse(response);
var statusAprovacao = responseObj.statusAprovacao;
Hope this helps!
For the elements you should call elements()
method to get the array object.
Try this.
var json = S(response);
var list = json.elements().get(0).prop("statusAprovacao")
why don't you try:
var list = json.Parse("type":"String","value":"Pre aprovado","valueInfo":{});
and then you get the value with
list.value