SppConvertTableToJson
Converts a DriveWorks table into a JSON structure, either an object or array.
By default, text within the table is automatically attempted to be parsed into JSON, use the overload parameter 'Convert JSON Text' to control this behavior.
Syntax
SppConvertTableToJson(Table, [Convert JSON Text])
Where:
Table is the table to convert.
Convert JSON Text (optional) will change the default behavior, set to FALSE to
avoid parsing text within the table to JSON even if it appears to be a JSON object or array.
Example 1 - Convert to JSON Object
Rule
SppConvertTableToJson(DWCalcOrderDetails)
Converts the calculation table named OrderDetails to a JSON Object.
A single JSON object is outputted due to the table only having 1 row.
Data
Calculation table named OrderDetails.
| Name | Description | Price | Created |
|---|
| Scissor Lift 4742 | 571mm wide, 478mm high, SWL 1000 kg. | 1469.56 | 10/03/2025 11:53:21 |
Result - Convert to JSON Object
Due to the table being a single row, the output is a JSON object:
{
"Name": "Scissor Lift 47421",
"Description": "571mm wide, 478mm high, SWL 1000 kg.",
"Price": 1469.56,
"Created": "2025-03-10T11:53:21.2108447+00:00"
}Example 2 - Convert to JSON Array
Rule
SppConvertTableToJson(DWCalcBillOfMaterials)
Converts the calculation table named BillOfMaterials to a JSON Array.
A JSON array is outputted due to the table having more than 1 row.
Data
Calculation table named BillOfMaterials
| Part ID | Description | Qty |
|---|
| MAH-RH-1161-596 | Mahogany panel right hand (1161 high x 596 deep) | 1 |
| HG762RT | Double folded recessed standard hinge | 4 |
Result - Convert to JSON Array
Due to the table being multiple rows, the output is a JSON array:
[
{
"Part ID": "MAH-RH-1161-596",
"Description": "Mahogany panel right hand (1161 high x 596 deep)",
"Qty": 1.0
},
{
"Part ID": "HG762RT",
"Description": "Double folded recessed standard hinge",
"Qty": 4.0
}
]Example 3 - Convert to JSON Object with Children
Rule
SppConvertTableToJson(DWCalcUserPermissions)
Converts the calculation table named UserPermissions, which includes a nested table within a cell, to a JSON Object with Children.
Data
Calculation table named UserPermissions.
| Permission | Users |
|---|
| Administrator | DWCalcUserPermissionsAdministrator |
Calculation table named UserPermissionsAdministrator.
| Login |
|---|
| justo@aol.couk |
| id.blandit.at@protonmail.edu |
Result - JSON Object with Children
{
"Permission": "Administrator",
"Users": [
{
"Login": "justo@aol.couk"
},
{
"Login": "id.blandit.at@protonmail.edu"
}
]
}Example 4 - Convert to JSON Object with Children (Text to JSON)
Rule
SppConvertTableToJson(DWCalcContacts, TRUE)
Converts the calculation table named Contacts, which includes text formatted as JSON within cells, to a JSON Object with Children.
Data
Calculation Table named Contacts.
| Name | Addresses |
|---|
| Jamie Bishop | "[{""Address Line 1"":""56 Argyll Road"",""Address Line 2"":null,""City"":""LLANDDEW"",""ZIP / Postal Code"":""LD3 1SL"",""Country"":""UK""},{""Address Line 1"":""77 Fordham Rd"",""Addres Line 2"":null,""City"":""HADLEIGH"",""ZIP / Postal Code"":""IP7 1JD"",""Country"":""UK""}]" |
| Abby Welch | "{""Name"":""Jamie Bishop"",""Addresses"":[{""Address Line 1"":""93 Newmarket Road"",""Address Line 2"":null,""City"":""HAWSTEAD"",""ZIP / Postal Code"":""IP29 7YD"",""Country"":""UK""},{""Address Line 1"":""38 Broad Street"",""Addres Line 2"":null,""City"":""LOWER SHIPLAKE"",""ZIP / Postal Code"":""RG9 5PX"",""Country"":""UK""}]}" |
Result - JSON Object with Children
[
{
"Name": "Jamie Bishop",
"Addresses": [
{
"Address Line 1": "56 Argyll Road",
"Address Line 2": null,
"City": "LLANDDEW",
"ZIP / Postal Code": "LD3 1SL",
"Country": "UK"
},
{
"Address Line 1": "77 Fordham Rd",
"Address Line 2": null,
"City": "HADLEIGH",
"ZIP / Postal Code": "IP7 1JD",
"Country": "UK"
}
]
},
{
"Name": "Abby Welch",
"Addresses": {
"Name": "Jamie Bishop",
"Addresses": [
{
"Address Line 1": "93 Newmarket Road",
"Addres Line 2": null,
"City": "HAWSTEAD",
"ZIP / Postal Code": "IP29 7YD",
"Country": "UK"
},
{
"Address Line 1": "38 Broad Street",
"Addres Line 2": null,
"City": "LOWER SHIPLAKE",
"ZIP / Postal Code": "RG9 5PX",
"Country": "UK"
}
]
}
}
]See Also