Spin: Reading complex json string using


#1

Hi
I need some help reading a json string using spin (i am using the derived value as expression to make decision).

Below is my json object with key and value. ->
key=caseObject
value=
{ "metadata": { "value": { "file_name": "mail_body_1536566790998" } }, "doc_state": { "value": "processed_ingest" }, "doc_id": { "value": "c19a0440-68c3-4488-b102-099b1a6acb28" }, "solution_id": { "value": "umad4_09dd6ffe-bd3b-4daf-9702-2db6cb26fae1" } }

I have tried below expressions:

 ${S('caseObject').prop('doc_state').get(0).value()=='processed_ingest'}
${S('caseObject').prop('doc_state').prop('value').value()=='processed_ingest'}
${S('caseObject').prop('doc_state').value().prop('value').value()=='processed_ingest'}
${S('caseObject').prop('doc_state.value').value()=='processed_ingest'}
${S(S('caseObject').prop('doc_state').value()).value()!='processed_ingest'}

None of these work.
Any kind of help is much appreciated.

PS: I have tried simpler jsons and it works. for example:

Key=
Value= {“k”:“v”}
Spin expression: ${S(‘key’).prop(‘k’).value()==‘v’}
(this one works)

Thanks
Urvashi


#2

Hi Urvashi,

What is the exception when you use ${S('caseObject').prop('doc_state').prop('value').value()=='processed_ingest'} ?

Cheers,
Thorben


#3

Hi Thorben

Thanks for responding. The error I was getting was some parse error.
It turned out to be a silly mistake.
It should have been

${S(caseObject).prop('doc_state').prop('value').value()=='processed_ingest'}

instead of
${S('caseObject').prop('doc_state').prop('value').value()=='processed_ingest'}

since caseObject is my variable name, i shouldn’t be putting it in quotes. only the json attributes should be in quotes.