Logesh
Logesh

Reputation: 45

Marklogic Java Client Json to HTML

In marklogic 8, trying to get the Query search result in JSON format. Is that possible/available to transform JSON to HTML using java client. Using ServerTransform and xsl i am able to transform XML to HTML. please share any reference document link if available.

Upvotes: 1

Views: 114

Answers (2)

Please see the reply from David Cassel.

However, if you have already built the tool to transform from XML to HTML, then perhaps all you need to do is implement the JSON-XML step just before that. For MarkLogic, there is already a very robust library to transform from JSON to XML. The function is: json:transform-from-json

This library has lots of options on how to handle the transform (like how to represent an array, even the ability to store some json properties as attributes and others as child elements, etc). For all of this, json:config is your friend.

I suggest that you start with a blank slate json:config("custom") - which makes no assumptions. Then build out the details of the transformation as you need.

Lastly, it is worth noting that the library can also transform XML to JSON very nicely.

Upvotes: 2

Dave Cassel
Dave Cassel

Reputation: 8422

JSON is a data transmission format and you're probably best off thinking of it that way. I would lean toward converting from JSON to HTML in your presentation layer (likely JSP or JavaScript) and letting the communication between your Java layer and MarkLogic remain in JSON.

If you're going to build the HTML using Java, including JSP, then you can use Jackson to switch from JSON to Java objects, then use these to build up your presentation.

If you're going to do it in JavaScript, there's no need to transform, as JavaScript is great for working with JSON. In this case, exactly how you do it will depend on what JavaScript framework or libraries you are using, if any.

Upvotes: 2

Related Questions