Class TinyPath
TinyPath is a minimal JSON path expression language designed for IoT scenarios. Expressions are compiled once and can be evaluated repeatedly against different inputs.
TinyPath path = TinyPath.compile("$[\"sensors\"][0][\"value\"]");
String value = path.evaluate(json, String.class);
-
Method Summary
Modifier and TypeMethodDescriptionstatic TinyPathCompiles a TinyPath expression.<T> TEvaluates this expression against the given JSON string and converts the result to the specified type.<T> TEvaluates this expression against a pre-parsedJsonNodeand converts the result to the specified type.toString()Returns the original expression string.
-
Method Details
-
compile
Compiles a TinyPath expression.- Parameters:
expression- the TinyPath expression string- Returns:
- a compiled
TinyPathinstance - Throws:
TinyPathException- if the expression contains a syntax error
-
evaluate
Evaluates this expression against the given JSON string and converts the result to the specified type.Returns
nullwhen the path does not resolve — for example, when a field is missing, an array index is out of bounds, or a filter has no match.If you need to evaluate multiple expressions against the same JSON data, prefer
evaluate(JsonNode, Class)with a pre-parsedJsonNodeto avoid parsing the JSON string repeatedly.- Type Parameters:
T- the expected result type- Parameters:
json- the JSON string to evaluate againsttype- the expected result type class (e.g.String.class,Integer.class)- Returns:
- the value at the path, or
nullif the path does not resolve - Throws:
TinyPathException- if the JSON string is invalid
-
evaluate
Evaluates this expression against a pre-parsedJsonNodeand converts the result to the specified type.Use this overload when evaluating multiple expressions against the same JSON data, so the JSON string is parsed only once via
Json.MAPPER.Returns
nullwhen the path does not resolve — for example, when a field is missing, an array index is out of bounds, or a filter has no match.- Type Parameters:
T- the expected result type- Parameters:
root- the pre-parsed JSON tree to evaluate againsttype- the expected result type class (e.g.String.class,Integer.class)- Returns:
- the value at the path, or
nullif the path does not resolve
-
toString
-