jmespath.cpp
C++ implementation of JMESPath, a query language for JSON http://jmespath.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Classes | Functions
The public API of the library

Classes

class  jmespath::Expression
 The Expression class represents a JMESPath expression. More...
 

Functions

template<typename JsonT >
std::enable_if_t< std::is_same
< std::decay_t< JsonT >, Json >
::value, Json > 
jmespath::search (const Expression &expression, JsonT &&document)
 Finds or creates the results for the expression evaluated on the given document. More...
 

Detailed Description


Class Documentation

class jmespath::Expression

The Expression class represents a JMESPath expression.

The Expression class can be used to store a parsed JMESPath expression and reuse it for multiple searches.

Note
This class is reentrant.

Public Member Functions

 Expression ()
 Constructs an empty Expression object. More...
 
 Expression (const Expression &other)
 Constructs a copy of other. More...
 
 Expression (Expression &&other)
 Move-constructs an Expression by moving the value of other to this object. More...
 
template<typename U , typename std::enable_if< std::is_convertible< U, String >::value >::type * = nullptr>
 Expression (U &&expression)
 Constructs an Expression object by forwarding argument. More...
 
Expressionoperator= (const Expression &other)
 Assigns other to this expression and returns a reference to this expression. More...
 
Expressionoperator= (Expression &&other)
 Move-assigns other to this expression and returns a reference to this expression. More...
 
bool operator== (const Expression &other) const
 Equality compares this expression to the other. More...
 
String toString () const
 Converts the expression to the string representation of the JMESPath expression. More...
 
bool isEmpty () const
 Checks whether this object has been initialized. expression. More...
 
const ast::ExpressionNodeastRoot () const
 Returns a pointer to the root expression in the abstract syntax tree. More...
 

Private Member Functions

void parseExpression (const String &expressionString)
 Parses the expressionString and updates the AST. More...
 

Private Attributes

String m_expressionString
 The string representation of the JMESPath expression. More...
 
std::unique_ptr
< ast::ExpressionNode,
ExpressionDeleter
m_astRoot
 The root node of the ast. More...
 

Constructor & Destructor Documentation

jmespath::Expression::Expression ( )

Constructs an empty Expression object.

jmespath::Expression::Expression ( const Expression other)

Constructs a copy of other.

Parameters
[in]otherThe object that should be copied.
jmespath::Expression::Expression ( Expression &&  other)

Move-constructs an Expression by moving the value of other to this object.

Parameters
[in]otherThe object whose value should be mvoed.
template<typename U , typename std::enable_if< std::is_convertible< U, String >::value >::type * = nullptr>
jmespath::Expression::Expression ( U &&  expression)
inline

Constructs an Expression object by forwarding argument.

This constructor participates in overload resolution only if U is implicitly convertible to String. Argument should describe a valid JMESPath expression.

Parameters
[in]argumentThe value that should be forwarded.
Template Parameters
UThe type of argument.
Exceptions
SyntaxErrorWhen the syntax of the specified expression is invalid.

Member Function Documentation

const ast::ExpressionNode * jmespath::Expression::astRoot ( ) const

Returns a pointer to the root expression in the abstract syntax tree.

Returns
A pointer to the root expression or nullptr if the object is empty.
bool jmespath::Expression::isEmpty ( ) const

Checks whether this object has been initialized. expression.

Returns
Returns true the expression has not been initialized yet, otherwise returns false.
Expression & jmespath::Expression::operator= ( const Expression other)

Assigns other to this expression and returns a reference to this expression.

Parameters
[in]otherThe expression that should be assigned.
Returns
Reference to this expression.
Expression & jmespath::Expression::operator= ( Expression &&  other)

Move-assigns other to this expression and returns a reference to this expression.

Parameters
[in]otherThe expression that should be moved.
Returns
Reference to this expression.
bool jmespath::Expression::operator== ( const Expression other) const

Equality compares this expression to the other.

Parameters
[in]otherThe expression that should be compared.
Returns
Returns true if this object is equal to the other, otherwise false
void jmespath::Expression::parseExpression ( const String expressionString)
private

Parses the expressionString and updates the AST.

Parameters
[in]expressionStringThe string representation of the JMESPath expression.
Exceptions
SyntaxErrorWhen the syntax of the specified expressionString is invalid.
String jmespath::Expression::toString ( ) const

Converts the expression to the string representation of the JMESPath expression.

Returns
[in] String representation of the JMESPath expression.

Member Data Documentation

std::unique_ptr<ast::ExpressionNode, ExpressionDeleter> jmespath::Expression::m_astRoot
private

The root node of the ast.

String jmespath::Expression::m_expressionString
private

The string representation of the JMESPath expression.

Function Documentation

template<typename JsonT >
std::enable_if_t< std::is_same< std::decay_t< JsonT >, Json >::value, Json > jmespath::search ( const Expression &  expression,
JsonT &&  document 
)

Finds or creates the results for the expression evaluated on the given document.

The expression string should be encoded in UTF-8.

Parameters
expressionJMESPath expression.
documentInput JSON document
Returns
Result of the evaluation of the expression in Json format
Note
This function is reentrant. Since it takes the expression by reference the value of the expression should be protected from changes until the function returns.
Exceptions
InvalidAgrumentIf a precondition fails. Usually signals an internal error.
InvalidValueWhen an invalid value is specified for an expression. For example a 0 step value for a slice expression.
UnknownFunctionWhen an unknown JMESPath function is called in the expression.
InvalidFunctionArgumentArityWhen a JMESPath function is called with an unexpected number of arguments in the expression.
InvalidFunctionArgumentTypeWhen an invalid type of argument was specified for a JMESPath function call in the expression.