Working with JSON
Some REST clients use XML and some use JSON to exchange data. In this recipe, we will look at how to parse and construct JSON objects in Orchestrator.
Getting ready
You should be comfortable with the recipe JavaScript complex variables in this chapter before starting this recipe.
How to do it...
We will divide this recipe into multiple sections, each of which will deal with the different aspects of JSON.
Parsing JSON REST returns
The (undocumented) JSON.parse
function makes an object out of a JSON string. This is typically used with JSON REST returns.
In this example, we look at the REST return from the Control Center GET call: api/server/status
.
The method response.contentAsString
returns the following string:
{"id":null,"error":null,"warning":null,"requestedStatus":null,"initialStatu s":"RUNNING","currentStatus":"RUNNING","progress":"Status-ing tcServer\nInstance name: app...