Skip to content

A fully compliant implementation of JMESPATH for .NetCore

License

Notifications You must be signed in to change notification settings

drmacm/JmesPath.Net

 
 

Repository files navigation

JMESPath.Net

A fully compliant implementation of JMESPath for .Net Core.

Build status

Getting started

Using the parser

JMESPath.Net uses Newtonsoft.Json to handle JSON and comes with a simple to use parser:

using DevLab.JmesPath;

const string input = @"{ \"foo\": \"bar\" }";
const string expression = "foo";

var jmes = new JmesPath();
var result = jmes.Transform(input, expression);

The JmesPath.Transform method accepts and produces well formed JSON constructs (object, array or string, boolean, number and null values). In the example above, the result is a JSON string token, including the quotes.

using Newtonsoft.Json.Linq;

System.Diagnostics.Debug.Assert(result == "\"bar\"");

var token = JToken.Parse(result);
var text = token.ToString();

System.Diagnostics.Debug.Assert(text == "bar");

Exploiting the AST

The previous example return the result of the JMESPath evaluation in a single function call. The JMESPath.Net parser, however, create an abstract syntax tree with a root JmesPathExpression object used for evaluating JMESPath expression against a JSON document.

If you want to retrieve the AST before performing evaluations, use the following code:

var jp = new JmesPath();
var ast = jp.Parse(expression);

System.Diagnostics.Debug.Assert(ast is JmesPathExpression);

Here is the inheritance hierarchy of JmesPathExpression objects:

classDiagram
	class JmesPathExpression
	JmesPathExpression: +bool IsExpressionType()
    JmesPathExpression <|-- JmesPathSimpleExpression
    JmesPathExpression <|-- JmesPathCompoundExpression
    JmesPathExpression <|-- JmesPathProjection
    JmesPathExpression <|-- JmesPathFunctionExpression
    JmesPathExpression <|-- JmesPathLetExpression
    JmesPathExpression <|-- JmesPathVariableReference

	JmesPathFunctionExpression: +string Name
	JmesPathFunctionExpression: +JmesPathExpression[] Arguments
Loading

Leaf Expressions

classDiagram
    JmesPathExpression <|-- JmesPathCurrentNode
    JmesPathExpression <|-- JmesPathIdentifier
    JmesPathExpression <|-- JmesPathIndex
    JmesPathExpression <|-- JmesPathLiteral
    JmesPathExpression <|-- JmesPathMultiSelectHash
    JmesPathExpression <|-- JmesPathMultiSelectList
    JmesPathExpression <|-- JmesPathRawString

	JmesPathMultiSelectList: +JmesPathExpression[] Expressions
	JmesPathMultiSelectHash: +IDictionary~string, JmesPathExpression~ Dictionary
	JmesPathIdentifier: +string Name
	JmesPathIndex: +int Index
	JmesPathLiteral: +JToken Value
	JmesPathRawString: + string Value
Loading

Simple Expressions

A simple expression encapsulates a single instance of another expression named Expression.

classDiagram
	class JmesPathSimpleExpression
	JmesPathSimpleExpression: +JmesPathExpression Expression

	JmesPathSimpleExpression <|-- JmesPathNotExpression
	JmesPathSimpleExpression <|-- JmesPathParenExpression
Loading

Compound Expressions

Compound expressions are a combination of two expressions, named Left and Right.

classDiagram
	class JmesPathCompoundExpression
	JmesPathCompoundExpression: +JmesPathExpression Left
	JmesPathCompoundExpression: +JmesPathExpression Right

	JmesPathCompoundExpression <|-- JmesPathAndExpression
	JmesPathCompoundExpression <|-- JmesPathComparison
	JmesPathCompoundExpression <|-- JmesPathIndexExpression
	JmesPathCompoundExpression <|-- JmesPathOrExpression
	JmesPathCompoundExpression <|-- JmesPathPipeExpression
	JmesPathCompoundExpression <|-- JmesPathSubExpression
Loading
classDiagram
	JmesPathProjection <|-- JmesPathFilterProjection
	JmesPathProjection <|-- JmesPathFlattenProjection
	JmesPathProjection <|-- JmesPathHashWildcardProjection
	JmesPathProjection <|-- JmesPathListWildcardProjection
	JmesPathProjection <|-- JmesPathSliceProjection

	JmesPathFilterProjection: +JmesPathExpression Expression
	JmesPathSliceProjection: +int? Start
	JmesPathSliceProjection: +int? Stop
	JmesPathSliceProjection: +int? Step
Loading
classDiagram
	JmesPathComparison <|-- JmesPathEqualOperator
	JmesPathComparison <|-- JmesPathOrderingComparison
	JmesPathComparison <|-- JmesPathNotEqualOperator
Loading
classDiagram
	JmesPathOrderingComparison <|-- JmesPathGreaterThanOperator
	JmesPathOrderingComparison <|-- JmesPathGreaterThanOrEqualOperator
	JmesPathOrderingComparison <|-- JmesPathLessThanOperator
	JmesPathOrderingComparison <|-- JmesPathLessThanOrEqualOperator
Loading

About

A fully compliant implementation of JMESPATH for .NetCore

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 95.1%
  • Yacc 2.4%
  • PowerShell 1.5%
  • Lex 1.0%