JsonToken.SelectToken(Text, var JsonToken) Method

Version: Available or changed with runtime version 1.0.

Selects a JsonToken using a JPath expression.


[Ok := ]  JsonToken.SelectToken(Path: Text, var Result: JsonToken)


 Type: JsonToken
An instance of the JsonToken data type.

 Type: Text
A valid JPath expression.

 Type: JsonToken
A JsonToken variable that will contain the result if the operation is successful.

Return Value

[Optional] Ok
 Type: Boolean
true if the read was successful; otherwise, false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.


The operation will fail if more or less than 1 tokens are the result of evaluating the JPath.


The following example shows how to select a value from a complex JSON Object. We build up a select expression in the query variable, we select the token corresponding to the salary of the employee with the given employeeId, and finally, we convert the token to a Decimal value.

We assume that the company token contains JSON data similar to the one below.

{ "company": {
    "employees": [
      { "id": "Marcy",
        "salary": 8.95
      { "id": "John",
        "salary": 7
      { "id": "Diana",
        "salary": 10.95
local procedure SelectEmployeeSalary(companyData : JsonToken; employeeId : Text) salary : Decimal;
    query : Text;
    salaryToken : JsonToken;
    query := '$.company.employees[?(@.id=='''+employeeId+''')].salary';
    companyData.SelectToken(query, salaryToken);

    salary := salaryToken.AsValue().AsDecimal();    


Ensure that the selected expression contains ' (single quotation mark) and not " (double quotation mark) to decorate the string value.

See Also

JsonToken Data Type
Get Started with AL
Developing Extensions