JSON Data Types and Functions
- Updated2025-10-31
- 2 minute(s) read
Use the PAscript JSON functions and the data types to build JSON strings.
Introduced in PAtools 2025 Q2
Example: Accessing SystemLink API Endpoints Using a JSON Body
Note The following example assumes that a
OrgDaten_SystemLink_TestPlanId.TXT name is defined in the
test that contains the SystemLink test plan ID.
Note Refer to the HTTP API Reference in the
SystemLink API Reference for more information about using the HTTP
API with sys:systemLink:request.
program
section globals
text OrgDaten_SystemLink_TestPlanId.TXT
endsection
// 1. Get the test plan
int32 httpStatusCode
jsonValue testPlanValue
jsonValue none
text getSubPath(50) = "niworkorder/v1/testplans/" + OrgDaten_SystemLink_TestPlanId.TXT
[testPlanValue, httpStatusCode] = sys:systemLink:request(systemLink:httpVerbs:GET, getSubPath, none)
if httpStatusCode != 200 then
sys:logInfo(sys:ui, "Get test plan failed with http status %i", httpStatusCode)
return
endif
// 2. Write test plan json to file
jsonSerializer serializer
serializer:writeToFile("/home/patools/systemlink/testplan.json", testPlanValue)
// 3. Evaluate test plans state property
jsonObject testPlan = testPlanValue:getValueAsJsonObject()
jsonValue state = testPlan:getValue("state")
text stateText(20) = state:getValueAsText()
if stateText != "IN_PROGRESS" then
sys:logInfo(sys:ui, "Unexpected test plan state: %s", stateText)
return
endif
// 4. Evaluate test plan properties
jsonValue propertiesValue = testPlan:getValue("properties")
jsonObject properties = propertiesValue:getValueAsJsonObject()
jsonMember m
foreach m in properties:getMembers()
text name(10) = m:getName()
if name == "StartTime" then
jsonValue startTime = m:getValue()
text startTimeText(30) = startTime:getValueAsText()
sys:logInfo(sys:ui, "Test plan start time: %s", startTimeText)
break
endif
endforeach
// 5. Add EndTime as property to the test plan
// 5.1 Edit the test plan
timestamp now = sys:calender:time
text timeText(30) = sprintf("%i/%i/%i %02i:%02i:%02i", now:month, now:day, now:year, now:hour, now:minute, now:second)
jsonValue time(timeText)
properties:addOrSetValue("EndTime", time)
// 5.2 Build the request body using edited test plan
jsonObject updateRequest
jsonArray testPlans
testPlans:addValue(testPlanValue)
jsonValue testPlansValue(testPlans)
updateRequest:addOrSetValue("testPlans", testPlansValue)
jsonValue updateRequestValue(updateRequest)
jsonValue updateTestPlanResponse
[updateTestPlanResponse, httpStatusCode] = sys:systemLink:request(systemLink:httpVerbs:POST, "niworkorder/v1/update-testplans", updateRequestValue)
// 6. Transition test plan state from "In progress" to "Pending approval"
jsonObject executeRequest
jsonValue end("END")
executeRequest:addOrSetValue("Action", end)
text executeSubPath(50) = "niworkorder/v1/testplans/" + OrgDaten_SystemLink_TestPlanId.TXT + "/execute"
jsonValue executeRequestValue(executeRequest)
jsonValue executeTestPlanResponse
[executeTestPlanResponse, httpStatusCode] = sys:systemLink:request(systemLink:httpVerbs:POST, executeSubPath, executeRequestValue)
endprogram
The example JSON test plan that is used in 1-4:
{
"id": "1000",
"name": "Battery Cycle Test",
"state": "IN_PROGRESS",
"properties":
{
"Location": "Austin",
"Cost Center": "12345"
}
}
The example JSON test plan request that is used in 5:
{
"testPlans": [
{
"id": "1000",
"name": "Battery Cycle Test",
"state": "IN_PROGRESS",
"properties": {
"Location": "Austin",
"Cost Center": "12345",
"EndTime": "3/24/2025 15:49:04"
}
}
]
}
The example JSON execute test plan action request that is used in 6:
{
"action": "END"
}