Class TinyPath
java.lang.Object
com.dcsuibian.tinypath.TinyPath
A compiled TinyPath expression that can be evaluated against JSON data.
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 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.- 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
-
toString
-