1.0.1 • Published 1 year ago

jsonpath-pg v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

jsonpath-pg

npm version ci

jsonpath-pg is a lightweight Node.js package that compiles the JSONPath parsing C code from the PostgreSQL source codebase into WebAssembly. It exposes an easy-to-use interface for converting JSONPath expressions into an Abstract Syntax Tree (AST).

Note: This package requires Node.js v16+.

Features

  • Uses PostgreSQL's JSONPath parsing code to ensure accurate and efficient parsing, notability the grammar and lexer files
  • Converts the C code into WebAssembly for performance and easy integration with Node.js
  • Provides a simple and user-friendly interface

Installation

Install the package using npm:

npm install jsonpath-pg

Usage

Import the jsonpathToAst function and use it to parse JSONPath expressions:

import { jsonpathToAst } from 'jsonpath-pg';

const expression = '$.hello.world';
const ast = jsonpathToAst(expression);

console.log(JSON.stringify(ast, null, 2));

This will output the following AST:

{
  "expr": [
    {
      "type": "$"
    },
    {
      "type": ".key",
      "value": "hello"
    },
    {
      "type": ".key",
      "value": "world"
    }
  ],
  "lax": true
}

Example 2

import { jsonpathToAst } from 'jsonpath-pg';

const expression = '$.track ? (exists(@.segments[*] ? (@.HR > 130))).segments.size()';
const ast = jsonpathToAst(expression);

console.log(JSON.stringify(ast, null, 2));

API

jsonpathToAst(expression: string): object

Parses a JSONPath expression into an AST.

Arguments:

  • expression (string): The JSONPath expression to parse.

Returns:

An object representing the AST of the parsed JSONPath expression.

Errors:

If the given string cannot be parsed as a valid JSONPath expression, then throws an InvalidJsonpathExpression error.

1.0.1

1 year ago

1.0.1-beta.1

1 year ago

1.0.0

1 year ago

1.0.0-beta.2

1 year ago

1.0.0-beta.1

1 year ago

0.0.1-alpha.1

1 year ago

0.0.1-alpha.0

1 year ago