Implementation of the JMES Path JSON Query language for Java
npx @tessl/cli install tessl/maven-com-amazonaws--jmespath-java@1.12.0A comprehensive Java implementation of the JMESPath JSON query language specification, enabling developers to extract and transform data from JSON documents using path expressions. This library provides a complete query engine that supports JMESPath's full syntax including field access, array indexing, slicing, projections, filtering, and built-in functions for data manipulation.
<dependency><groupId>com.amazonaws</groupId><artifactId>jmespath-java</artifactId><version>1.12.791</version></dependency>import com.amazonaws.jmespath.JmesPathExpression;
import com.amazonaws.jmespath.JmesPathEvaluationVisitor;
import com.amazonaws.jmespath.InvalidTypeException;For building expressions:
import com.amazonaws.jmespath.*;
import com.fasterxml.jackson.databind.JsonNode;import com.amazonaws.jmespath.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
// Create JSON data
ObjectMapper mapper = new ObjectMapper();
JsonNode data = mapper.readTree("{\"users\": [{\"name\": \"Alice\", \"age\": 30}, {\"name\": \"Bob\", \"age\": 25}]}");
// Create evaluation visitor
JmesPathEvaluationVisitor visitor = new JmesPathEvaluationVisitor();
// Build and execute expression
JmesPathExpression expr = new JmesPathSubExpression(
new JmesPathField("users"),
new JmesPathProjection(
new JmesPathIdentity(),
new JmesPathField("name")
)
);
// Evaluate expression
JsonNode result = expr.accept(visitor, data);
// Result: ["Alice", "Bob"]The library is built around the Visitor Pattern as its core architectural design:
JmesPathExpression implementations representing query componentsJmesPathVisitor defines operations for processing different expression typesJmesPathEvaluationVisitor traverses expressions and evaluates them against JSON dataJsonNode integration for JSON processingThe fundamental interface for all JMESPath expressions, providing the entry point for the visitor pattern.
public interface JmesPathExpression {
<Input, Output> Output accept(JmesPathVisitor<Input, Output> visitor, Input input)
throws InvalidTypeException;
}The primary visitor implementation for evaluating JMESPath expressions against JSON data, supporting all expression types and operations.
public class JmesPathEvaluationVisitor implements JmesPathVisitor<JsonNode, JsonNode> {
public JsonNode visit(JmesPathField fieldNode, JsonNode input);
public JsonNode visit(JmesPathSubExpression subExpression, JsonNode input) throws InvalidTypeException;
public JsonNode visit(JmesPathProjection jmesPathProjection, JsonNode input) throws InvalidTypeException;
// ... additional visit methods for all expression types
}Comprehensive set of comparison operators for filtering and conditional operations, including equality, numeric comparisons, and logical operations.
public abstract class Comparator implements JmesPathExpression {
public Comparator(JmesPathExpression lhsExpr, JmesPathExpression rhsExpr);
public abstract boolean matches(JsonNode lhs, JsonNode rhs);
}
public class OpEquals extends Comparator {
public OpEquals(JmesPathExpression lhsExpr, JmesPathExpression rhsExpr);
public boolean matches(JsonNode lhs, JsonNode rhs);
}
public abstract class NumericComparator extends Comparator {
public abstract boolean matches(BigDecimal lhs, BigDecimal rhs);
}Extensible function system with built-in implementations for common operations like length calculation and containment checking.
public abstract class JmesPathFunction implements JmesPathExpression {
public JmesPathFunction(List<JmesPathExpression> expressions);
public abstract JsonNode evaluate(List<JsonNode> evaluatedArgs);
}
public class JmesPathLengthFunction extends JmesPathFunction {
public JmesPathLengthFunction(JmesPathExpression... expressions);
public JsonNode evaluate(List<JsonNode> evaluatedArgs) throws InvalidTypeException;
}
public class JmesPathContainsFunction extends JmesPathFunction {
public JmesPathContainsFunction(JmesPathExpression... expressions);
public JsonNode evaluate(List<JsonNode> evaluatedArgs);
}Complex expression types for sophisticated JSON querying including projections, filters, logical operations, and array manipulations.
public class JmesPathProjection implements JmesPathExpression {
public JmesPathProjection(JmesPathExpression lhsExpr, JmesPathExpression projectionExpr);
}
public class JmesPathValueProjection implements JmesPathExpression {
public JmesPathValueProjection(JmesPathExpression lhsExpr, JmesPathExpression rhsExpr);
}
public class JmesPathFlatten implements JmesPathExpression {
public JmesPathFlatten(JmesPathExpression toFlatten);
}
public class JmesPathFilter implements JmesPathExpression {
public JmesPathFilter(JmesPathExpression lhsExpr, JmesPathExpression rhsExpr,
JmesPathExpression comparator);
}
public class JmesPathAndExpression implements JmesPathExpression {
public JmesPathAndExpression(JmesPathExpression lhsExpr, JmesPathExpression rhsExpr);
}
public class JmesPathNotExpression implements JmesPathExpression {
public JmesPathNotExpression(JmesPathExpression expr);
}public class InvalidTypeException extends RuntimeException {
public InvalidTypeException(String message);
public InvalidTypeException(String message, Throwable t);
public InvalidTypeException(Throwable t);
}JMESPath operations may throw InvalidTypeException when:
public final class ObjectMapperSingleton {
public static ObjectMapper getObjectMapper();
}The library provides a singleton ObjectMapper for consistent JSON processing throughout the expression evaluation system.