I want to know what is the best way to convert XML to JSON in MarkLogic.
I use json:transform-to-json, but it does not give the proper response. Also it slows the service response a lot.
My XML has attributes or you can say search:search response data.
Related
Sorry for the inappropriate question. But what do you recommend me to use to structure a library that can put a query arrangement on json formats generated by an XML parsing based on TEI p5? I tried to use GraphQL by converting the interfaces of my Angular application related to parsing information from XML to JSON in type to define a GraphQL schema but I don't think that's the way.
What I have to do is query, client only, some data encoded in XML (also wanting already parsed in JSON) and, for example, search for all occurrences of a specific data.
Do you have any roadmaps to recommend or some JSON query system that might be right for me?
You might take a look at https://www.npmjs.com/package/saxon-js. With SaxonJS you're able to run XPath expression against XML using JavaScript.
I Have a SOAP web services which takes XML as input and send XML as response. Now I have a JSON object which is the same as XML request. How can I convert JSON Object to XML so that I can send the XML request to my SOAP web service. I have the WSDL file. In other terms, I wanted to provide a extra layer of REST on top of SOAP
A JSON object can never be "the same as" an XML document, because the data models are different. It may hold the same information, but the problem is that there is no definitive mapping from JSON to XML that is guaranteed to produce the XML representation that you are after.
There are a number of libraries available that do JSON to XML conversion: give them a try, but you will probably have to "tweak" the XML to get it into the required form. That can always be done using XSLT, of course.
If you use XSLT 3.0 then you can do the JSON to XML conversion and subsequent processing ("tweaking") in a single step.
I'm working on a project where I ideally need to return a JSON object in an HTTP response where one field points to an xml snippet as a value. The object would look something like the following.
{
"driver1_url" : "https://driver.url.download.link",
"driver2_url" : "https://driver2.url.download.link",
"xml_snippet" : "<xml><snippet>value</snippet></xml>"
}
The xml snippet could be pretty long. Is it considered bad practice to embed XML into a JSON object? And if so, is there a better way to achieve what I've described?
It's not "bad" to add an XML string as a JSON value. It's only inconvenient if other programmers have to use your JSON response, because now they'd need an XML parser in addition to JSON abilities in their own programs. If you're the only one using JSON with XML values, then go ahead, have fun. It's your project, there's no wrong way to use these interchange formats so long as it works for your project and there's no expected need for compatibility with other systems.
If best practices are your concern, though, it is ideal to use either strict JSON or strict SOAP (the XML sibling of JSON, so to speak) for maximum compatibility.
I want to load an xml file and convert it into JSON in angularjs on the client side.
You have two options.
Return the data from the API in format you require to prevent conversions (recommended).
Convert the XML to JSON using javascript.
For approach #2 I'll recommend you this solution http://goessner.net/download/prj/jsonxml/
And please be sure to read the article 'Converting Between XML and JSON' (by Stefan Goessner) to overview details of the problems with conversions.
Hi I am new to Java and not sure how to proceed (kindly ignore any typos or my language). Can somebody help me out (just the Idea/how to proceed, dont need any sample code). I am trying to create a Restful Json webservice (using Spring MVC).
The webservice that I am trying to create is kind of a wrapper for an existing XML based restful webservice.
The Idea is to have one common platform, since all other existing services are exposed as as JSON services.
My job is to fetch the XML transform it into a Json, but the tricky part is The Json schema is a superset of the XML schema (I mean it contains more elements that get filled with some default values).
Please let me know if you need more info.
Thanks in advance.
One way to do it would be to use Jaxb to transform the the incoming XML to Java Objects. Build your Jaxb objects in a way that it contains all the elements, the one with default values and the elements in the incoming XML.
Ones the XMl is converted into Jaxb you can use org.springframework.http.converter.json.MappingJacksonHttpMessageConverter message converter to convert your Jaxb object to Json string.