Skip to main content

Evaluate Expression

Evaluates a boolean expression and optionally returns the result with variable substitutions. Supports Boolean expression parsing with AND, OR, and NOT operators.

Request

GET /nxt?requestType=evaluateExpression&expression=<expr>&evaluate=<boolean>&vars=<var1>&vars=<var2>&values=<val1>&values=<val2>

Parameters

NameTypeRequiredDescription
expressionstringConditionalBoolean expression to evaluate.
evaluatebooleanNoIf true, evaluates the expression with the provided variable values.
varsstring[]ConditionalVariable names (required if evaluate = true). May be repeated.
valuesstring[]ConditionalVariable values (TRUE or FALSE). Must correspond 1:1 with vars. May be repeated.

Response

With evaluate = true

{
"result": true,
"variables": ["A", "B", "C"],
"literalsCount": 3
}

With evaluate = false

{
"variables": ["A", "B", "C"],
"literalsCount": 3
}

Response Fields

FieldTypeDescription
resultbooleanResult of the expression evaluation (only present if evaluate = true).
variablesarray of stringsVariables extracted from the expression.
literalsCountintegerNumber of literals in the expression.

Error Responses

ConditionResponse
vars and values count mismatch{"error": "Vars undefined or number of vars differs from number of values"}
Invalid boolean value{"error": "<value> does not represent a valid boolean value..."}
Expression syntax errorBoolean expression error response

Notes

  • This endpoint does not require the blockchain to be running (requireBlockchain = false).
  • Not chain-specific.
  • Does not require admin password authentication (requirePassword = false).

Source: EvaluateExpression.java.

Example

curl "http://localhost:22024/nxt?requestType=evaluateExpression&expression=A%20AND%20B&evaluate=true&vars=A&vars=B&values=TRUE&values=FALSE"