Clarion JSON & XML Mixed

Good day,

I have the following JSON which also contains XML inside it. Is it possible to process the JSON and XML Together?

{
“totalRecords”: 1117,
“success”: true,
“data”: [
{
“ItemCode”: “0000000000000P88”,
“ItemDescription”: “SS-CRATES REC/RET”,
“HQCost”: 5,
“ingredients”: “”
},
{
“ItemCode”: “000000000ABC1006”,
“ItemDescription”: “SNACK - wings”,
“HQCost”: 10.3364,
“ingredients”: “0000000KMI0500531.0000000000000KMI0533011.0000000000000KMI0535550.0220000000000KMI0560532.0000000000000KMI0613140.0300000000000KMI0613560.0266800000000KMI0711040.0320000000000KMI0718730.000560000000KMI010021A4.000000”
}
]
}

Hi @AdriaanDup30

{
        "totalRecords": 1117,
        "success": true,
        "data": [
            {
                "ItemCode": "0000000000000P88",
                "ItemDescription": "SS-CRATES REC/RET",
                "HQCost": 5,
                "ingredients": ""
            },
            {
                "ItemCode": "000000000ABC1006",
                "ItemDescription": "SNACK - wings",
                "HQCost": 10.3364,
                "ingredients": "0000000KMI0500531.0000000000000KMI0533011.0000000000000KMI0535550.0220000000000KMI0560532.0000000000000KMI0613140.0300000000000KMI0613560.0266800000000KMI0711040.0320000000000KMI0718730.000560000000KMI010021A4.000000"
            }
        ]
    }

I’ve reformatted the above and I am not seeing any XML within that JSON, is there more of an example?

Regards

Mark

1 Like

Good day Mark,

Apologies for the incorrect JSON.

Please see below:

> {
>         "totalRecords": 1117,
>         "success": true,
>         "data": [
> {
> 			"ItemCode": "000000000ABC1006",
> 			"ItemDescription": "SNACK - 4 DUNKED WINGS",
> 			"HQCost": 10.3364,
> 			"ingredients": "<explosion><ingredient><code>0000000KMI050053</code><qty>1.000000</qty></ingredient><ingredient><code>0000000KMI053301</code><qty>1.000000</qty></ingredient><ingredient><code>0000000KMI053555</code><qty>0.022000</qty></ingredient><ingredient><code>0000000KMI056053</code><qty>2.000000</qty></ingredient><ingredient><code>0000000KMI061314</code><qty>0.030000</qty></ingredient><ingredient><code>0000000KMI061356</code><qty>0.026680</qty></ingredient><ingredient><code>0000000KMI071104</code><qty>0.032000</qty></ingredient><ingredient><code>0000000KMI071873</code><qty>0.000560</qty></ingredient><ingredient><code>000000KMI010021A</code><qty>4.000000</qty></ingredient></explosion>"
> 		},
> 		{
> 			"ItemCode": "000000000ABC1012",
> 			"ItemDescription": "A.M KRUSHER -VERRY BERRY",
> 			"HQCost": 7.6039,
> 			"ingredients": "<explosion><ingredient><code>0000000KMI051942</code><qty>0.045000</qty></ingredient><ingredient><code>0000000KMI052055</code><qty>0.027000</qty></ingredient><ingredient><code>0000000KMI052064</code><qty>0.050000</qty></ingredient><ingredient><code>0000000KMI052120</code><qty>1.000000</qty></ingredient><ingredient><code>0000000KMI052125</code><qty>1.000000</qty></ingredient><ingredient><code>0000000KMI091016</code><qty>0.090000</qty></ingredient><ingredient><code>0000000KMI093037</code><qty>1.000000</qty></ingredient><ingredient><code>000000KMI056046A</code><qty>0.500000</qty></ingredient></explosion>"
> 		}
>         ]
>     }

Hi

Given my toolset, I would use jFiles2 to parse the json into the structures, Bruce provides a nice tool to work the structures out here.

I would then loop through the queue for the data array and parse the value of ingredients with xFiles.

So the answer isn’t quite can it be done in one line of code, but it’s not hard to do either.

Mark

3 Likes

Thank you very much.