Friday, 18 November 2022

How to convert items that are returned as an XML string rather than JSON?

I am having the following issue :

BE is returning a JSON file that has keys and values but some values are in XML format. How can I turn them into JSON as well ?

It's the first time I am seeing this kind of structure. So any help would be appreciated. I am working on in a React environment.

[{
    "price": 19,
    "currency": "GBP",
    "productImage": "https://daye.cdn.prismic.io/daye/ee153f6163435330b18495535217c531300382a8_product2x.png",
    "items": [
        {
            "size": "regular",
            "coating": "none",
            "amount": 8
        },
        {
            "size": "regular",
            "coating": "CBD",
            "amount": 4
        }
    ]
},
{
    "price": 18,
    "currency": "GBP",
    "productImage": "https://daye.cdn.prismic.io/daye/ee153f6163435330b18495535217c531300382a8_product2x.png",
    "items": "<items><item><size>regular</size><coating>none</coating><amount>10</amount></item><item><size>regular</size><coating>CBD</coating><amount>2</amount></item></items>"
},
{
    "price": 19,
    "currency": "GBP",
    "productImage": "https://daye.cdn.prismic.io/daye/ee153f6163435330b18495535217c531300382a8_product2x.png",
    "items": [
        {
            "size": "small",
            "coating": "none",
            "amount": 8
        },
        {
            "size": "small",
            "coating": "CBD",
            "amount": 4
        }
    ]
},
{
    "price": 18,
    "currency": "GBP",
    "productImage": "https://daye.cdn.prismic.io/daye/ee153f6163435330b18495535217c531300382a8_product2x.png",
    "items": "<items><item><size>small</size><coating>none</coating><amount>10</amount></item><item><size>small</size><coating>CBD</coating><amount>2</amount></item></items>"
},
{
    "price": 17,
    "currency": "GBP",
    "productImage": "https://daye.cdn.prismic.io/daye/ee153f6163435330b18495535217c531300382a8_product2x.png",
    "items": "<items><item><size>regular</size><coating>none</coating><amount>12</amount></item></items>"
},
{
    "price": 17,
    "currency": "GBP",
    "productImage": "https://daye.cdn.prismic.io/daye/ee153f6163435330b18495535217c531300382a8_product2x.png",
    "items": "<items><item><size>small</size><coating>none</coating><amount>12</amount></item></items>"
}]


from How to convert items that are returned as an XML string rather than JSON?

No comments:

Post a Comment