---
title: "Converting JSON to XML"  
description: "Converting JSON to XML"  
author: "Takeshi Okada"  
published: 2013-05-16  
updated: 2018-05-21  
canonical: https://www.mindstick.com/forum/893/converting-json-to-xml  
category: "facebook api"  
tags: ["facebook api"]  
reading_time: 1 minute  

---

# Converting JSON to XML

Hi Expert! \
I trying to [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) JSON output into XML. Unfortunately I get this error:\
JSON root object has [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) properties. The root object must have a single [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) in order to create a valid XML document. Consider specifing a DeserializeRootElementName.\
This is what I up to now created.\
string url = [string.Format](https://www.mindstick.com/forum/1763/string-format-with-null-values-c-sharp)("https://graph.facebook.com/{0}?fields=posts.fields(message)&access_token={1}", user_name, access_token);\
HttpWebRequest [request](https://www.mindstick.com/blog/255/post-get-and-request-function-in-php) = WebRequest.Create(url) as HttpWebRequest;\
using (HttpWebResponse [response](https://www.mindstick.com/forum/12719/how-to-make-response-write-display-special-character-like-lt-gt) = request.GetResponse() as HttpWebResponse) { [StreamReader](https://www.mindstick.com/forum/161576/explain-the-difference-between-streamreader-and-file-readalllines) reader = new StreamReader(response.GetResponseStream()); jsonOutput = reader.ReadToEnd(); Console.WriteLine("THIS IS JSON OUTPUT: " + jsonOutput); } XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonOutput); Console.WriteLine(doc);And this is my JSON output:\
{"id":"108013515952807","posts":{"data":[{"id":"108013515952807_470186843068804","created_time":"2013-05-14T20:43:28+0000"},\
{"message":"TEKST","id":"108013515952807_470178529736302","created_time":"2013-05-14T20:22:07+0000"}How can I [solve this problem](https://answers.mindstick.com/qa/94681/my-google-assistant-shows-completely-different-search-results-from-what-i-ask-how-can-i-solve-this-problem)?\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)! \
\

## Replies

### Reply by Ella Scott

Post is removed by the Admin.

### Reply by AVADHESH PATEL

Hi Takeshi!\
Despite the fact your JSON provided in the question is not complete, you have multiple properties at the top level as indicated by the exception. \
You have to define the root for it to get valid XML:\
var doc = JsonConvert.DeserializeXmlNode(jsonOutput, "root");


---

Original Source: https://www.mindstick.com/forum/893/converting-json-to-xml

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
