Skip to content

Instantly share code, notes, and snippets.

@sdurandeu
Created February 15, 2013 18:12
Show Gist options
  • Save sdurandeu/4962217 to your computer and use it in GitHub Desktop.
Save sdurandeu/4962217 to your computer and use it in GitHub Desktop.
Json to XML using Newtonsoft.Json
namespace JsonToXml
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Newtonsoft;
using System.IO;
class Program
{
static void Main(string[] args)
{
// load json
string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.txt");
foreach (string file in files)
{
using (StreamReader streamReader = new StreamReader(file))
{
// convert it
XmlDocument doc = (XmlDocument)Newtonsoft.Json.JsonConvert.DeserializeXmlNode(streamReader.ReadToEnd(), "Operations");
// save it
XmlTextWriter writer = new XmlTextWriter(file.Replace(".txt",".xml"), null);
writer.Formatting = Formatting.Indented;
doc.Save(writer);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment