Introduction

edit

Meziantou.Framework.JsonPath finds values in JSON with JSONPath queries such as $.store.book[?@.price < 10].title. It implements the JSONPath standard, RFC 9535, for the System.Text.Json types and for any object model you expose to it.

What you can do with it

  • Query JSON: select values by member name, index, slice, wildcard or at any depth, and filter them with comparisons, logical operators and functions. See Query syntax and Filters.
  • Use the standard functions: length(), count(), match(), search() and value(), with I-Regexp (RFC 9485) regular expressions. See Functions.
  • Opt in to domain-specific functions using an immutable typed registry. See Register custom functions.
  • Evaluate on the type you already have: JsonNode, JsonDocument or JsonElement. Every match comes with its normalized path, such as $['store']['book'][0]. See Evaluating queries.
  • Choose how missing data is reported: by default a member or an element that does not exist selects nothing; in strict mode it throws. See Errors and evaluation modes.
  • Query your own object model without converting it to JSON first. See Custom object models.

Principles

  • Standard JSONPath. The library follows RFC 9535 and is tested against the JSONPath Compliance Test Suite. Queries written for other JSONPath dialects may need changes; see Limitations.
  • Invalid queries are rejected. JsonPath.Parse throws on a query that is not well-formed and valid, instead of guessing what it means.
  • Parse once, evaluate many times. A JsonPath is immutable and thread-safe: keep it and reuse it for any number of documents, from any thread.
  • Results keep the document order. The matches are returned in the order the query selects them, each with the normalized path that leads to it.

Namespaces

NamespaceContains
Meziantou.Framework.JsonJsonPath, the results, the evaluation modes, the extension methods and the navigator for custom object models
System.Text.Json and System.Text.Json.NodesThe JSON types the queries are evaluated on: JsonDocument, JsonElement, JsonNode

Next steps