Reading data from JSON/XML from Service Suite
You
can read JSON data from a file and convert it into a JavaScript object using the following example:
// Read the JSON file and convert its contents to a string.
var $aJsonString = new java.lang.String(
readBytes("{mds}/somejsonfile.json")
);
// Parse the JSON string into a JavaScript object.
var jsonObj = JSON.parse($aJsonString);
The
performs two steps:
- Read the file:
readBytes()reads the contents of the JSON file. The contents are converted to a JavaString. - Parse the JSON:
JSON.parse()converts the JSON string into a JavaScript object, allowing you to access individual values from the JSON data.
For example, if the JSON file contains:
{
"username": "mauricio",
"environment": "QA"
}
You can access its values through the resulting object:
log(jsonObj.username);
log(jsonObj.environment);
This produces:
mauricio
QA
Last updated: FebruaryAugust 22,13, 20232026
If you have any feedback on this topic, please contact us at documentation@appvance.ai.