in Education by
I'm a new programmer and I'm really stuck (likely being so new and having so little knowledge) I need to convert a json string (something like this): [ { "Start": "date", "Finish": "date", "Subject": "", "Comments": "", "Site": "address", "Location": null, "Status": false, "Arrived": true, "Noshow": false, "Services": "Initial Consultation", "Attendees": [ { "AccountId": 1111, "AccountType": "MP", "Name": "MMS (FP), Support " }, { "AccountId": 2220915, "AccountType": "PA", "Name": "Test, Patient " } ] }, ] into XML like this: <?xml version="1.0" encoding="UTF-8"?> true 1111 MP MMS(FP), Support 2220915 PA Test, Patient date false Initial Consultation address date false ` And have tried Googling various answers to no avail. I've tried lots of permutations of JsonConvert.DecryptXmlNode(filename); but these all through up errors. The errors I've had include "Data at root level is invalid." and "Can only convert json that begins with a valid object". For the purposes of clarification, I've been sent hundreds of Json files (no idea what is in them) and need a sort of 'catch all' scenario. Thank you in advance. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Before you start, I recommend validating your JSON using https://jsonlint.com/. The outer square brackets are not necessary, and the trailing comma at the end should ideally be removed. Now, since you mentioned you are using C# and Newtonsoft Json.NET, you could try this in a console program's Program.cs file: using System; using System.Xml.Linq; //For the XDocument class using Newtonsoft.Json; //For JsonConvert class using System.IO; //For File class class JsonToXMLProgram { static void Main(string[] args) { string myJSONString = @File.ReadAllText(@"H:\MyJsonFile.json"); //Replace with your json files' locations. //This converts the JSON string to xml XDocument myXMLDocument = JsonToXML(myJSONString); //you could then check your xml by outputting it to the console... Console.WriteLine(myXMLDocument.ToString()); //..or by saving the file to disk string myXMLFilePath = @"H:\MyXmlDocument.xml"; //Replace with the path to your generated xml files. myXMLDocument.Save(myXMLFilePath); } public static XDocument JsonToXML(string jsonString) { XDocument xmlDoc; try { xmlDoc = JsonConvert.DeserializeXNode(jsonString, "Root", true); return xmlDoc; } catch (JsonException e) { Console.WriteLine("There appears to be an error in the json file. Please validate the json to ensure that it is free from errors."); Console.WriteLine("Details: " + e.Message); return new XDocument(); } } }

Related questions

0 votes
    I'm a new programmer and I'm really stuck (likely being so new and having so little knowledge) I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    When working with Ajax applications, which is faster, XML or JSON? A. XML, because it is extensible B. JSON, ... D. JSON, because it is already parsed into a JavaScript object...
asked Mar 10, 2023 in Technology by JackTerrance
0 votes
    How to get ASP.NET Web API to return JSON instead of XML using Chrome?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    I am inserting JSON string into table, than on listing page in View inside foreach loop I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I am using a framework, which returns invalid JSON String like: /* { "myobject" : "test"} */ ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    How to convert JSON string into an object?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    I have a variable, in which is a XML string. In this XML string, I want iterate through a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    _______is the syntax to read JSON data?...
asked Mar 4, 2023 in Technology by JackTerrance
0 votes
    I have a CLOB column with the following data (simplified for the purposes of this question) { "notUsed" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have json file as follows: { "status":"UP", "diskSpace": {"status":"UP","total":63279460352," ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    I have this JSON tree view that represents a menu : var menus = [ { label : "1", items: [ ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    i am using serilog in asp net core application and using a json formatter to create a daily log file ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    I been receiving date in the "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" format from JSON input, which gets ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I have an incoming json object that represents the data pulled from a database structure. I would like to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 24, 2022 in Education by JackTerrance
...