Converts JSON (array or object) into a DriveWorks table.
Note: 3-dimensional array elements are returned as a string.
The function returns a table.
If the JSON is not valid an error string is returned.
SppConvertJsonToTable([JSON])
Where:
JSON is the JSON as a string to convert.
When passing JSON Objects or Arrays, blank values must be defined as null.
For example:
{"title":"Harry Potter","price":null}
However, JSON Literals will convert blank values in the table.
For example:
[3,,5]
Since DriveWorks tables are only two-dimensional, any third dimension (children) of an array is converted to a string within its parent.
As such, blank values are converted to undefined for children.
For example:
{"title":"Harry Potter","price":[20,35,,16]}
Will be converted to:
title | price |
---|---|
Harry Potter | [20,35,undefined,16] |
This function validates the JSON being passed into it in accordance with ECMA 404 - The JSON Data Interchange Standard.
Invalid JSON will return the following error result:
#SPPCONVERTJSONTOTABLE! Invalid JSON.
Note: A single object is converted to a one row table.
Table headers are taken from property names.
The following JSON Object data is stored in the constant DWConstantJSONObject.
DWConstantJSONObject |
---|
{"title":"Harry Potter","price":29.99} |
Rule |
---|
SppConvertJsonToTable(DWConstantJSONObject) |
title | price |
---|---|
Harry Potter | 29.99 |
Note: A single object is converted to a one row table.
Table headers are taken from property names.
Since DriveWorks tables are only two-dimensional, any third dimension (children) of an array is converted to a string within its parent.
The following JSON Object data is stored in the constant DWConstantJSONObject.
DWConstantJSONObject |
---|
{"title":"Harry Potter", "tags": ["fantasy","wizard"], "inStock":true} |
Rule |
---|
SppConvertJsonToTable(DWConstantJSONObject) |
title | tags | inStock |
---|---|---|
Harry Potter | ["fantasy","wizard"] | true |
Note: A single row represents an object in the array, and the row order reflects the object’s position in the array.
Table headers are taken from the property names.
The following JSON Array data is stored in the constant DWConstantJSONArray.
DWConstantJSONArray |
---|
[{"title":"Harry Potter","price":29.99},{"title":"Learning JSON","price":39.95}] |
Rule |
---|
SppConvertJsonToTable(DWConstantJSONArray) |
title | price |
---|---|
Harry Potter | 29.99 |
Learning JSON | 39.95 |
Note: A single row represents an object in the array, and the row order reflects the object’s position in the array.
Table headers are taken from the property names.
Since DriveWorks tables are only two-dimensional, any third dimension (children) of an array is converted to a string within its parent.
The following JSON Array data is stored in the constant DWConstantJSONArray.
DWConstantJSONArray |
---|
[{"title":"Harry Potter","price":29.99},{"title":"Learning JSON","price":[29.99,39.95,30,40]}] |
Rule |
---|
SppConvertJsonToTable(DWConstantJSONArray) |
title | price |
---|---|
Harry Potter | 29.99 |
Learning JSON | [29.99,39.95,30,40] |
Note: Array literals are converted to a single column table with a blank header.
The following JSON Array Literal data is stored in the constant DWConstantJSONLiteral.
DWConstantJSONLiteral |
---|
[29.99,39.95,15.12,16] |
Rule |
---|
SppConvertJsonToTable(DWConstantJSONLiteral) |
29.99 |
39.95 |
15.12 |
16 |
The following functions may be of use when working with JSON.
Introduction to JSON - JSON.org
Online JSON validator - JSONLint - The JSON Validator
ECMA Interntaional - ECMA 404 - The JSON Data Interchange Standard.