{"id":3799,"date":"2017-07-06T08:06:35","date_gmt":"2017-07-06T15:06:35","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=3799"},"modified":"2025-06-13T20:57:05","modified_gmt":"2025-06-14T03:57:05","slug":"xml-json-conversion-json-net","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/","title":{"rendered":"Converting XML to JSON In C# Using Json.NET"},"content":{"rendered":"<div class=\"paragraph\">\n<div class=\"paragraph\">\n<p>Converting XML to JSON data that can be loaded into Couchbase Server <span style=\"font-weight: 400\">can be accomplished with a little bit of .NET<\/span>. Depending on the source of the data, you might be able to use a tool like <a href=\"https:\/\/docs.couchbase.com\/talend-connector\/index.html\">Talend<\/a>. But you may also want to write a simple C# .NET application with <a href=\"https:\/\/www.newtonsoft.com\/json\">Newtonsoft\u2019s Json.NET<\/a> to do it. <span style=\"font-weight: 400\">In this article, I\u2019m going to show you how to convert XML to JSON in C# using Json.NET.<\/span><\/p>\n<p><a href=\"https:\/\/resources.couchbase.com\/c\/10-nosql-use-cases-ebook?x=kS8g0a\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-14422 alignright\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/07\/image_2023-05-22_160947247-1024x559.png\" alt=\"10 Common NoSQL Use Cases for Modern Applications\" width=\"306\" height=\"167\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/image_2023-05-22_160947247-1024x559.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/image_2023-05-22_160947247-300x164.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/image_2023-05-22_160947247-768x419.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/image_2023-05-22_160947247.png 1225w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/a>Not using Couchbase Server? No problem, this is a pretty generic example. But consider the advantages of having a full-featured database using JSON at the center of your solution; indexing, querying, searching, analytics, mobile support are all built-in and accessible with a <a href=\"https:\/\/docs.couchbase.com\/dotnet-sdk\/current\/hello-world\/overview.html\">.NET SDK<\/a>. See more <a href=\"https:\/\/resources.couchbase.com\/c\/10-nosql-use-cases-ebook?x=kS8g0a\">advantages in our technical whitepaper<\/a> or <a href=\"https:\/\/www.couchbase.com\/downloads\/\">download Couchbase<\/a> and follow along with this post.<\/p>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_xml_data\">XML data<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>For the purposes of this tutorial, I\u2019m going to use a very simple XML example. If your XML is more complex (multiple attributes, for instance), then your approach will also have to be more complex. (Json.NET can handle all XML to Json conversions, but it follows a specific set of <a href=\"https:\/\/www.newtonsoft.com\/json\/help\/html\/ConvertingJSONandXML.htm\">conversion rules<\/a>). Here\u2019s a sample piece of data:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">            var xml = @\"\r\n&lt;Invoice&gt;\r\n    &lt;Timestamp&gt;1\/1\/2017 00:01&lt;\/Timestamp&gt;\r\n    &lt;CustNumber&gt;12345&lt;\/CustNumber&gt;\r\n    &lt;AcctNumber&gt;54321&lt;\/AcctNumber&gt;\r\n&lt;\/Invoice&gt;\";<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Notice that I\u2019ve got this XML as a hardcoded string in C#. In a real-life situation, you would likely be pulling XML from a database, a REST API, XML files, etc.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Once you have the raw XML, you can create an <code>XmlDocument<\/code> object (<code>XmlDocument<\/code> lives in the <code>System.Xml<\/code> namespace).<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">XmlDocument doc = new XmlDocument();\r\ndoc.LoadXml(xml);<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_conversion_with_json_net\">Conversion with Json.NET<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Once you have an <code>XmlDocument<\/code> object, you can use Json.NET to convert that object into a Json representation.<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">var json = JsonConvert.SerializeXmlNode(doc, Formatting.None, true);<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>In this example, I\u2019m asking Json.NET to serialize an XML node:<\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li>I used <code>Formatting.None<\/code>. If I wanted to display the actual Json, it might be better to use <code>Formatting.Indented<\/code><\/li>\n<li>The last <code>true<\/code> specifies that I want to omit the root object. In the XML above, you can think of <code>&lt;Invoice&gt;&lt;\/Invoice&gt;<\/code> as the root object. I just want the values of the Invoice object. If I didn\u2019t omit the root node, the resultant Json would look like: <code>{\"Invoice\":{\"Timestamp\":\"1\/1\/2017 00:01\",\"CustNumber\":\"12345\",\"AcctNumber\":\"54321\"}}<\/code><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_saving_the_json_result\">Saving the Json result<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Finally, let\u2019s put the Json into Couchbase. The easiest way to do this would be to again call on <code>JsonConvert<\/code> to deserialize the Json into a C# <code>object<\/code>. That object would then be used with Couchbase\u2019s <code>bucket.Insert(\u2026\u200b)<\/code> method.<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">object transactObject1 = JsonConvert.DeserializeObject(json);\r\nbucket.Insert(Guid.NewGuid().ToString(), transactObject1);<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>With this method, the Json would be stored in Couchbase like so:<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><span class=\"image\"><img decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/07\/07201-xml-to-json-object-storage.png\" alt=\"XML serialized to object\" \/><\/span><\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>That might be fine, but often times you\u2019re going to want more control of the format. With Json.NET, we can serialize to a given class, instead of just <code>object<\/code>. Let\u2019s create an <code>Invoice<\/code> class like so:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">public class Invoice\r\n{\r\n    public DateTime Timestamp { get; set; }\r\n    public string CustNumber { get; set; }\r\n    public int AcctNumber { get; set; }\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Notice that there is some type information now. The Timestamp is a <code>DateTime<\/code> and the AcctNumber is an <code>int<\/code>. The conversion will still work, but the result will be different, according to <a href=\"https:\/\/www.newtonsoft.com\/json\/help\/html\/ConvertingJSONandXML.htm\">Json.NET\u2019s conversion rules<\/a>. (Also check out the <a href=\"https:\/\/www.newtonsoft.com\/json\/help\/html\/Introduction.htm\">full Json.NET documentation<\/a> if you aren\u2019t familiar with it already).<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-C#\">Invoice transactObject2 = JsonConvert.DeserializeObject&lt;Invoice&gt;(json);\r\nbucket.Insert(Guid.NewGuid().ToString(), transactObject2);<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>The result of that insert will look like:<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><span class=\"image\"><img decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/07\/07202-xml-to-dotnet-object-storage.png\" alt=\"XML serialized to new class object\" \/><\/span><\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li>Notice that the timestamp field is different: it\u2019s stored in a more standardized way.<\/li>\n<li>The acctNumber field value is not in quotes, indicating that it\u2019s being stored as a number.<\/li>\n<li>Finally, notice that the field names are different. This is due to the way Json.NET names Json fields by default. You can specify different names by using the <code>JsonProperty<\/code> attribute.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_that_s_it\">That\u2019s it<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>One more minor thing to point out: I used <code>Guid.NewGuid().ToString()<\/code> to create arbitrary keys for the documents. If you have value(s) in the XML data that you want to use for a key, you could\/should use those value(s) instead.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>This blog post was inspired by an email conversation with a Couchbase user. If you have any suggestions on tools, tips, or tricks to make the process of converting XML to JSON easier, please let me know. Or, contact me if there\u2019s something you\u2019d like to see me blog about! You can <a href=\"mailto:matthew.groves@couchbase.com\">email me<\/a> or <a href=\"https:\/\/twitter.com\/mgroves\">contact me @mgroves on Twitter<\/a>.<\/p>\n<h2>Keep Learning<\/h2>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li>Read: <a href=\"https:\/\/resources.couchbase.com\/c\/10-nosql-use-cases-ebook?x=kS8g0a\">10 Common NoSQL Use Cases for Modern Applications<\/a><\/li>\n<li>Download: <a href=\"https:\/\/www.couchbase.com\/downloads\/\">Couchbase Server or get free trial of Capella DBaaS<\/a><\/li>\n<li>Watch the <a href=\"https:\/\/www.youtube.com\/watch?v=zoZW0tM6hwU&amp;t=528s\">Oracle to Couchbase Migration<\/a> YouTube video<\/li>\n<li>Watch The Register&#8217;s Career Development panel discuss <a href=\"https:\/\/resources.couchbase.com\/c\/video-career-development-developers?x=kS8g0a\">Three Ways Developers are Adapting to Change<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><iframe loading=\"lazy\" title=\"The Register - Career Development for Developers\" width=\"900\" height=\"506\" src=\"https:\/\/www.youtube.com\/embed\/1kHUwx3dXvY?start=1&#038;feature=oembed&#038;enablejsapi=1&#038;origin=https:\/\/www.couchbase.com\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Converting XML to JSON data that can be loaded into Couchbase Server can be accomplished with a little bit of .NET. Depending on the source of the data, you might be able to use a tool like Talend. But you [&hellip;]<\/p>\n","protected":false},"author":71,"featured_media":14424,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1811,10127,1816,1819],"tags":[1261,1747],"ppma_author":[8937],"class_list":["post-3799","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-c-sharp","category-couchbase-server","category-data-modeling","tag-json","tag-xml"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Convert XML to JSON In C# Using Json.NET | Couchbase Guide<\/title>\n<meta name=\"description\" content=\"Follow the necessary steps to convert XML to JSON in C# using Json.NET with this guide from Couchbase. We are here to make data work best for you.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Converting XML to JSON In C# Using Json.NET\" \/>\n<meta property=\"og:description\" content=\"Follow the necessary steps to convert XML to JSON in C# using Json.NET with this guide from Couchbase. We are here to make data work best for you.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-07-06T15:06:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T03:57:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/XML-to-JSON-in-C.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Matthew Groves\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mgroves\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Matthew Groves\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/\"},\"author\":{\"name\":\"Matthew Groves\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\"},\"headline\":\"Converting XML to JSON In C# Using Json.NET\",\"datePublished\":\"2017-07-06T15:06:35+00:00\",\"dateModified\":\"2025-06-14T03:57:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/\"},\"wordCount\":728,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/XML-to-JSON-in-C.png\",\"keywords\":[\"JSON\",\"XML\"],\"articleSection\":[\".NET\",\"C#\",\"Couchbase Server\",\"Data Modeling\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/\",\"name\":\"Convert XML to JSON In C# Using Json.NET | Couchbase Guide\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/XML-to-JSON-in-C.png\",\"datePublished\":\"2017-07-06T15:06:35+00:00\",\"dateModified\":\"2025-06-14T03:57:05+00:00\",\"description\":\"Follow the necessary steps to convert XML to JSON in C# using Json.NET with this guide from Couchbase. We are here to make data work best for you.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/XML-to-JSON-in-C.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/XML-to-JSON-in-C.png\",\"width\":1200,\"height\":628,\"caption\":\"Convert XML to {JSON} in C# using Json.NET\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Converting XML to JSON In C# Using Json.NET\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\",\"name\":\"Matthew Groves\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ba51e6aacc53995c323a634e4502ef54\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g\",\"caption\":\"Matthew Groves\"},\"description\":\"Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.\",\"sameAs\":[\"https:\/\/crosscuttingconcerns.com\",\"https:\/\/x.com\/mgroves\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/matthew-groves\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Convert XML to JSON In C# Using Json.NET | Couchbase Guide","description":"Follow the necessary steps to convert XML to JSON in C# using Json.NET with this guide from Couchbase. We are here to make data work best for you.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/","og_locale":"en_US","og_type":"article","og_title":"Converting XML to JSON In C# Using Json.NET","og_description":"Follow the necessary steps to convert XML to JSON in C# using Json.NET with this guide from Couchbase. We are here to make data work best for you.","og_url":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/","og_site_name":"The Couchbase Blog","article_published_time":"2017-07-06T15:06:35+00:00","article_modified_time":"2025-06-14T03:57:05+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/XML-to-JSON-in-C.png","type":"image\/png"}],"author":"Matthew Groves","twitter_card":"summary_large_image","twitter_creator":"@mgroves","twitter_misc":{"Written by":"Matthew Groves","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/"},"author":{"name":"Matthew Groves","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58"},"headline":"Converting XML to JSON In C# Using Json.NET","datePublished":"2017-07-06T15:06:35+00:00","dateModified":"2025-06-14T03:57:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/"},"wordCount":728,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/XML-to-JSON-in-C.png","keywords":["JSON","XML"],"articleSection":[".NET","C#","Couchbase Server","Data Modeling"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/","url":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/","name":"Convert XML to JSON In C# Using Json.NET | Couchbase Guide","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/XML-to-JSON-in-C.png","datePublished":"2017-07-06T15:06:35+00:00","dateModified":"2025-06-14T03:57:05+00:00","description":"Follow the necessary steps to convert XML to JSON in C# using Json.NET with this guide from Couchbase. We are here to make data work best for you.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/XML-to-JSON-in-C.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/07\/XML-to-JSON-in-C.png","width":1200,"height":628,"caption":"Convert XML to {JSON} in C# using Json.NET"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/xml-json-conversion-json-net\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Converting XML to JSON In C# Using Json.NET"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58","name":"Matthew Groves","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ba51e6aacc53995c323a634e4502ef54","url":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","caption":"Matthew Groves"},"description":"Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.","sameAs":["https:\/\/crosscuttingconcerns.com","https:\/\/x.com\/mgroves"],"url":"https:\/\/www.couchbase.com\/blog\/author\/matthew-groves\/"}]}},"authors":[{"term_id":8937,"user_id":71,"is_guest":0,"slug":"matthew-groves","display_name":"Matthew Groves","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","author_category":"","last_name":"Groves","first_name":"Matthew","job_title":"","user_url":"https:\/\/crosscuttingconcerns.com","description":"Matthew D. Groves is a guy who loves to code.  It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything.  He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s.  He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community.  He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/3799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/71"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=3799"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/3799\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/14424"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=3799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=3799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=3799"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=3799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}