# How can i Convert XML to JSON

**URL:** <https://community.thunkable.com/t/how-can-i-convert-xml-to-json/1805103>\
**Category:** Questions about Thunkable X\
**Tags:** json, object, xml\
**Created:** [March 28, 2022, 1:53am UTC](https://community.thunkable.com/t/how-can-i-convert-xml-to-json/1805103 "2022-03-28T01:53:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [March 28, 2022, 1:53am UTC](https://community.thunkable.com/t/how-can-i-convert-xml-to-json/1805103/1 "2022-03-28T01:53:02Z")

</div>

I’m trying to grab images from Flickr API, it returns it in XML format but they also have an argument for format=json

I get the following when I submit it

jsonFlickrApi({“photos”:{“page”:1,“pages”:547568,“perpage”:1,“total”:547568,“photo”:[{“id”:“51964262546”,“owner”:“194499057@N06”,“secret”:“fb65aea0be”,“server”:“65535”,“farm”:66,“title”:“Shark In The Water”,“ispublic”:1,“isfriend”:0,“isfamily”:0}]},“stat”:“ok”})

I have it set to a single photo just for my own clarity but I cannot get this to convert to an object to grab the properties.

No matter what I try I get null.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/0/20ee374a67c90d2195312a0d56c878696a155932.jpeg)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 28, 2022, 2:27am UTC](https://community.thunkable.com/t/how-can-i-convert-xml-to-json/1805103/2 "2022-03-28T02:27:24Z")

</div>

That’s not valid JSON. It’s not formatted properly. You should be able to paste the JSON response text into [Best JSON Viewer and JSON Beautifier Online](https://codebeautify.org/jsonviewer) and see the “tree” of values on the right side. Once you’ve got that working, post the corrected text and we can help you with the get property blocks.

**Edit:** sorry! Stupid [smart quotes](https://dan.hersam.com/tools/smart-quotes.php). The JSON is fine:

`{"photos":{"page":1,"pages":547568,"perpage":1,"total":547568,"photo":[{"id":"51964262546","owner":"194499057@N06","secret":"fb65aea0be","server":"65535","farm":66,"title":"Shark In The Water","ispublic":1,"isfriend":0,"isfamily":0}]},"stat":"ok"}`

The problem is that the “photo” property is an array/list. So you need to get the first list item of “photo” before you get the “id” property of that item.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/b/8b47e40e729a987f4272623977771432a406f9fb.png)

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [March 28, 2022, 3:16am UTC](https://community.thunkable.com/t/how-can-i-convert-xml-to-json/1805103/3 "2022-03-28T03:16:42Z")

</div>

Sorry I wasn’t aware of the smart quotes issue.

I used the links you provided and I see the difference.

I tried getting #1 of the list as follows but no cigar.  
Am I able to upload this object to the cloud as well like this?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/7/878931699f36c8f37458c9e9de5d23e8335bd3ad.jpeg)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 28, 2022, 3:54am UTC](https://community.thunkable.com/t/how-can-i-convert-xml-to-json/1805103/4 "2022-03-28T03:54:03Z")

</div>

> [@overshield](#):
>
> Sorry I wasn’t aware of the smart quotes issue.

Not your fault. Just something the forum software does for some reason. You can avoid it by using the Preformatted text icon in the forum toolbar:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/2/62e93c730ca1cd5d85922fc5a637ff6697f3b209.png)

> [@overshield](#):
>
> I tried getting #1 of the list as follows but no cigar.

That should work. I’ll create a quick demo to test it.

> [@overshield](#):
>
> Am I able to upload this object to the cloud as well like this?

You can upload just about anything to Firebase. So yes, you can upload an object to a cloud variable if that’s what you’re asking.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 28, 2022, 4:00am UTC](https://community.thunkable.com/t/how-can-i-convert-xml-to-json/1805103/5 "2022-03-28T04:00:31Z")

</div>

I used the same blocks and it worked, displaying “51964262546”.

See the first screen here:

[https://x.thunkable.com/copy/23638b6eaeaff97201b52337651a0152](https://x.thunkable.com/copy/23638b6eaeaff97201b52337651a0152)

So, since the JSON is valid and the blocks work, it means you need to do two things:

1. Check the value of the green error block to see if the API server is working properly. Assign that block to a label to check it.
2. Check the value of the green response block. Assign that block to a text input and then copy and paste the value into [Best JSON Viewer and JSON Beautifier Online](https://codebeautify.org/jsonviewer) to see if it recognizes it as valid JSON.

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [March 28, 2022, 4:13am UTC](https://community.thunkable.com/t/how-can-i-convert-xml-to-json/1805103/6 "2022-03-28T04:13:51Z")

</div>

Thank you, I copied your blocks and got the same result as you.

When going back to the green response block it was null again. I found that I had to remove `jsonFlickrApi` and the () and then it worked as intended

Is there a way to exclude jsonFlickrApi() to avoid this in the future?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [March 28, 2022, 6:29am UTC](https://community.thunkable.com/t/how-can-i-convert-xml-to-json/1805103/7 "2022-03-28T06:29:09Z")

</div>

If this is part of the response then use the `substring` block to get only the part you need from the response.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/1/81264c897c693cf63a6d46040f83d2777527e922.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [June 26, 2022, 6:29am UTC](https://community.thunkable.com/t/how-can-i-convert-xml-to-json/1805103/8 "2022-06-26T06:29:15Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
