JSON Content Model
The JSON Content Model is used to provide support for JSON format content. This provides a basic API to allow callers to extract values on the assumption that they know which values are to be accessed.
API
| Return | Method | Description |
|---|---|---|
String |
getJSONAsString() |
Returns the JSON content as a string. |
Object |
getObjectAt(<List of cbjecta> path, JSONArtifact artifact) throws
Exception |
Returns the object at the specified path. The supplied root artifact may be null in which case the root of the content is used. The returned value may be a literal string, integer, real or boolean, or a JSON artifact (either a JSON object or a JSON array). |
Hash table (key:object, value:object> |
getChildValuesAt(<List of object> path, JSONArtifact artifact) throws
Exception |
Returns the child values of the specified path if the path leads to a JSON object or null otherwise. The keys in the table are strings while the associated value may be a literal string, integer, real or boolean, or a JSON artifact (either a JSON object or a JSON array). |
List of objects |
getChildrenAt(<List of object> path path, JSONArtifact artifact) throws
Exception |
Returns the list of objects at the specified path if the path leads to a JSON array or null otherwise. The returned values may be a literal string, integer, real or boolean, or a JSON artifact (either a JSON object or a JSON array). |
void |
reset() |
Flushes any internal storage associated with this content model (for example, a cached DOM object). |
Example script
If there's an output builder node that creates output based on JSON format, you could use the following to access information about a set of books:
results = []
outputbuilder.run(results)
output = results[0]
cm = output.getContentModel("jsonContent")
bookTitle = cm.getObjectAt(["books", "ISIN123456", "title"], None)
# Alternatively, get the book object and use it as the root
# for subsequent entries
book = cm.getObjectAt(["books", "ISIN123456"], None)
bookTitle = cm.getObjectAt(["title"], book)
# Get all child values for aspecific book
bookInfo = cm.getChildValuesAt(["books", "ISIN123456"], None)
# Get the third book entry. Assumes the top-level "books" value
# contains a JSON array which can be indexed
bookInfo = cm.getObjectAt(["books", 2], None)
# Get a list of all child entries
allBooks = cm.getChildrenAt(["books"], None)