How to Use JSON Path

Use Cases and Tools

  • JSONPath is used for querying and filtering JSON in databases (PostgreSQL JSONPath, SQLite’s json_extract subset), CLIs (kubectl), API tooling (OpenAPI Overlays, Spectral), REST clients (Insomnia, Bruno), and localization of JSON fields.
  • Several tools support JSONPath-like syntax or JSON querying: jsonata (functional query/transform language, Turing-complete), jq-like fq for many binary formats, visualization/editors (OK JSON), schema/size profilers (json_profile), and libraries focused on path-based access (unify-jdocs).
  • Some projects convert JSON to XML DOM to reuse XPath/CSS selectors instead of inventing new DSLs.

Data Model and Cross-Format Paths

  • JSON and similar formats (YAML, TOML, Python dicts) are seen as tree-structured, “nested maps/arrays,” “documents,” “semi-structured data,” or “general-purpose hierarchical data formats.”
  • XML differs by interleaving text and elements; that is ergonomically good for documents, but less aligned with typical programming data structures, which helped JSON win for machine data.
  • A truly generic path language across JSON/YAML/XML/etc. is debated: node types and data-type differences make a clean, shared abstraction hard.

Merits and Drawbacks of JSONPath-like DSLs

  • Critics argue these mini-languages add complexity and maintenance risk without beating normal code using comprehensions, map/filter, etc., especially when you need function calls, null-safety, or parameterization.
  • Supporters highlight:
    • Concise one-liners for CLIs and configs.
    • Reuse of the same query across languages, clients, and servers.
    • Restricted power (non–Turing-complete) for safety and analyzability.
    • Necessity in ecosystems where JSONPath is mandated (e.g., OpenAPI Overlays).

Security and Safety

  • Concerns are raised about future “JSONPath injection” analogous to XPath injection if user-supplied fragments are interpolated without parameterization.
  • It’s unclear whether the ecosystem will provide robust, standardized parameterized-query mechanisms.

Performance and Implementation Issues

  • One report suggests JSONPath usage in a Node service may cause slowdowns; others note performance is highly dependent on the specific implementation.

Ecosystem Fragmentation & Ergonomics

  • There are many incompatible syntaxes: JSONPath, jq, JMESPath (AWS), database-specific variants, making muscle memory difficult.
  • Some wish for a simpler, file-path-like JSON notation for error reporting and basic access.
  • LLMs are seen as helpful for generating/explaining JSONPath and regexes, especially for complex tree queries.