Converting JSON to XMl file - json

What will be the preferred way of converting JSON to XML file? Is it better to use web-service or any Java component? I tried using web-service and still wanted to cross-check if there is any other option to do this.

Convert JSON text contained in string json into an XML node
XmlDocument Xmldoc = JsonConvert.DeserializeXmlNode(json);
Here is the documentation:
Json to xml

Related

How to convert HTML to JSON string with C++?

I trying to convert some HTML string to JSON string and then to objects, to store any images data on some page to TXT file.
I used Curl to download the page data (and can use nlohmann/json to convert JSON strings to object)
Now I need some way to convert HTML String to JSON Objects or find a way to convert the relevant for me data (like and tags)
Thanks for help

How to omit fields when using camel-xmljson JAR to convert XML string to JSON string

XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setEncoding("UTF-8");
xmlJsonFormat.setForceTopLevelObject(true);
xmlJsonFormat.setTrimSpaces(true);
xmlJsonFormat.setSkipNamespaces(true);
xmlJsonFormat.setRemoveNamespacePrefixes(true);
Pool a XML file from source directory and transform it to JSON format before sending it to destination directory
from("file:/inn?noop=true").marshal(xmlJsonFormat)
.setHeader(Exchange.FILE_NAME, simple("${file:onlyname.noext}.json"))
.to("file:/out").end();
It works great when i want a JSON string right from a XML without using a POJO.
But now consider a XML where I would like to omit an element.
Should I use another lib but camel-xmljson?
Is this way the right way of accomplish it:
JAXB lib to get a POJO from XML
Jackson lib to get a JSON from POJO and with excluding POJO fields from marshalling
I understand, even I would try to avoid any POJO's in camel routes.
Having said that, I wont just straight way let the XML out. I would put a XSLT after the xmljson component, so that I can trim the xml for desired output.
Thanks gnanagurus! This is quite simple using XSLT. Moreover the xslt: component is included in the last version of the core of Camel.
I defined an xlst file 'transform.xsl' taht includes the field that is to be omited. And then defined the Camel route like that:
from("file:/inn?noop=true")
.to("xslt:file:src/transform.xsl")
.marshal(xmlJsonFormat)
.setHeader(Exchange.FILE_NAME, simple("${file:onlyname.noext}.json"))
.to("file:/out").end();

Convert XSD to JSON Schema

My application support XML and JSON content type. I have XSD to validate XML content. I want to convert XSD to create a JSON Schema. Can I achieve this functionality in using C# ?
There is a commercial .NET library XsdToJsonSchema that converts from XSD to JSON schema that seems to be close to what you are looking for. A code snippet from its page:
string xsd = File.ReadAllText("XMLFile1.xsd");
string jsonSchema = XsdToJsonSchema.XsdToJsonSchemaConverter.ConvertXsdToJsonSchema(xsd);

String XML to JSON conversion in .NET without using XmlDocument

I'm trying to find a more memory efficient solution for converting XML string to JSON string (and vice versa)
without using XmlDocument.
Currently, all 3rd party libraries i tried, expects XmlDocument as input.
Before I'm writing my own parser using XmlReader, i was wondering if anyone know of a out of the box solution?
What are you trying to do exactly: Generate JSON directly from XML or deserialize the XML string to an object and then serialize it to JSON?
If you need a XmlSerializer take a look into this one I created (it uses XmlReader internally), you can find the code and how to use it here:
XML serialization using Generics
I ended up writing my own thin LightXmlDocument which holds a tree of objects representing xml elements.
LoadXml method implemented using XmlReader, i'm reading the xml string and building the tree.
Tested with 10 threads each thread iterating 900 times over different xml sizes:

how to identify json object or json array from a json parsing text?

i hav one problem , i parsed xml using json parsing and get json text. now i have to get values from xml. from that json text how i can identify jsonObject, jsonArray etc...
If you're doing this with JavaScript in a browser, try parsing the XML using jQuery.