Skip to content

Json Pointer and Path

Santanu edited this page Feb 3, 2022 · 2 revisions

Values or part of values or parameters to functions in the LHS and RHS of expressions can be evaluated from json pointers or paths. The pointer or path is used to extract the actual values from the json node being passed to Hope during evaluation.

        final ObjectMapper mapper = new ObjectMapper();
        final JsonNode node = mapper.readTree("{ \"lhs\" : 94, \"rhs\" : 97 }");
        Assert.assertTrue( //Using Json Pointer
            HopeLangParser.builder()
                .build()
                .evaluate("'/lhs' < '/rhs'", node));
        Assert.assertTrue( //Using json path
            HopeLangParser.builder()
                .build()
                .evaluate("'$.lhs' < '$.rhs'", node));

In the above example the hope expression '/lhs' < '/rhs' or '$.lhs' < '$.rhs' evaluates to true as /lhs or $.lhs evaluates to 94 and /rhs or $.rhs evaluates to 97 from the eval time json { "lhs" : 94, "rhs" : 97 }.

Note

From Version 1.1.0 Hope supports JSON Pointers (RFC). Pointers fit better for the use-case, are more standardized and much more performant than most Json path implementations. As such Json Path support would be removed in a future version of Hope. All new code should use Json Pointers and not json paths.

Clone this wiki locally