Avatar of sudheer89
sudheer89 asked on

Json to Xml conversion

Hi, i am tryong to convert json output to xml. can you please explain me how i can do that in c#? and also what namespaces do i have to use to access the functions regarding the serialization and deserialization of the json. please explain it with some example.

thank you
C#Web Languages and Standards.NET ProgrammingMicrosoft Development

Avatar of undefined
Last Comment
Bob Learned

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ioannis Paraskevopoulos

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
sudheer89

i tried that above link but it is saying like jsonconvert was not there in the current context like that. is there any other way we can do that?
Scott Fell

Can you post a sample record in json and the output you desire.  I am not well versed in C# myself but converting from json to xml could be easy or complex depending on the data.  

If you start out with

{
     "person": {
      "id": "1",
      "name": "Alan",
      "role": "Admin1"
      }
}

is it ok to end up with

<person>
     <id>1</id>
     <name>Alan</name>
     <role>Admin1</role>
</person>

or do you need more detail in your xml?

I think if you can provide sample input and output, experts can help you code the conversion.
aikimark

@sudheer89

Is this a one-time conversion?

What have you found during your Internet/EE searches on the subject? There are a lot of hits when I did a search.  
Here is the most interesting/promising one:
http://blog.djekldevelopments.co.uk/?p=317 (conversion using Newtonsoft.Json namespace from http://james.newtonking.com/projects/json/help/)

Did anything you've tried come close to a solution?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
sudheer89

the one you show me is correct, but when i am trying to convert that code in the c# its giving the namespace errors and other things. so you please post that conversion code for me and the namespaces, references that are added before using these things. and also one more question i am hp UFT tool to automate the services. when i try to convert the data from json to xml it is saying that the data at the root node is invalid. do have any idea what is that error was?


thank you
Scott Fell

@sudheer89, do you want to open up this question or ask a new one?   I appreciate the points but did if did my answer give you what you needed?
Bob Learned

The first link from jyparask was a good one, and the code was clear, so if the NuGet package was installed, and the code was used, the only issue I could see is that your code was missing a using statement in order to reference JsonConvert.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.