for an application I am building an administration panel where a power user should be able to check the JSON structure of a selected object.
I would like to display the JSON object in a computed text field but display/format it nicely so it is better human readable, something similar as in pretty print.
Is there any function I could use in SSJS that results in something similar so I can use display json nicely in computed text / editable fields?
As Knut points out, you can certainly add
json2.js
to XPages; I've previously used an implementation as Marky Roden's post outlines. This is probably the "safest" way of doing so, from the SSJS side of things.It does ignore the included
fromJson
andtoJson
SSJS methods provided out of the box in XPages. While imperfect, they are functional, especially with the inclusion of Tommy Valand's fix snippet. Be advised, using Tommy's fix does wrap responses to ensure a proper JS object can be parsed by shoving an Array into an object with avalues
property for the array; so no direct pulling of an Array only.Additionally, I believe it would be useful to point out that a bean, providing a convenience method or two as wrappers to use either the
com.ibm.commons.util.io.json
methods to abstract the conversion method, or switching in something like Google GSON, might be more powerful and unified, based on your style of development.