AnsweredAssumed Answered

Parse JSON profile when structure of one element depends on another

Question asked by kartikay.nagal147205 on Aug 31, 2018
Latest reply on Sep 4, 2018 by kartikay.nagal147205

Hi All,

I am having a JSON which is loosely typed and also the structure or datatype of one element /id depends on value of another id. Below is the schema of JSON

{
"content": [
{
"id": "string",
"label": "string",
"type": "BOOLEAN",
"value":"string"
"actions": {
"configuration": {
"url": "string",
"method": "GET"
}
}
}
]
}

 

I have defined the qualifiers on label in order to map this JSON to XML. But issue is that based on "type" element the "value" element can be string or an object.

 

for example if type is "text" than value is string (as shown above) but if type is "Currency" the value tag is object as below

 

"value": {
"code": "USD",
"value": 2000
},

 

When trying to parse this JSON i am getting below error:

[Input ProfileLocation: Root/Object/content/Array/ArrayElement1/Object/value; DocumentLocation: /Root/Object/content/Array/ArrayElement1[6]/Object/value]: Expected simple value, found START_OBJECT

 

How can we parse such json? Any inputs will be useful , TIA.

Outcomes