Class TinyPath

java.lang.Object
com.dcsuibian.tinypath.TinyPath

public final class TinyPath extends Object
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

      public static TinyPath compile(String expression)
      Compiles a TinyPath expression.
      Parameters:
      expression - the TinyPath expression string
      Returns:
      a compiled TinyPath instance
      Throws:
      TinyPathException - if the expression contains a syntax error
    • evaluate

      public <T> T evaluate(String json, Class<T> type)
      Evaluates this expression against the given JSON string and converts the result to the specified type.

      Returns null when 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 against
      type - the expected result type class (e.g. String.class, Integer.class)
      Returns:
      the value at the path, or null if the path does not resolve
      Throws:
      TinyPathException - if the JSON string is invalid
    • toString

      public String toString()
      Returns the original expression string.
      Overrides:
      toString in class Object