@jsonpath-tools/codemirror-lang-jsonpath
v1.0.0
Published
JSONPath (RFC 9535) language support for CodeMirror editor.
Readme
@jsonpath-tools/codemirror-lang-jsonpath
JSONPath (RFC 9535) language support for CodeMirror editor.
Quickstart
Installation:
npm install @jsonpath-tools/codemirror-lang-jsonpathBasic usage:
import { EditorView, basicSetup } from "codemirror";
import {
jsonpath,
updateQueryOptionsEffect,
updateQueryArgumentEffect,
updateQueryArgumentTypeEffect
}
from "@jsonpath-tools/codemirror-lang-jsonpath";
import { defaultQueryOptions, jsonSchemaToType } from "@jsonpath-tools/jsonpath";
// Convert JSON Schema to a type.
const queryArgumentType = jsonSchemaToType({ schema: queryArgumentSchema });
// Create a CodeMirror editor with the `jsonpath` extension.
const editor = new EditorView({
doc: `$..inventory[[email protected][?@ == "Bluetooth"] && match(@.make, "[tT].+")]`,
extensions: [
basicSetup,
jsonpath()
],
parent: document.getElementById("app")!
});
// Dispatch configuration.
editor.dispatch({
effects: [
updateQueryOptionsEffect.of(defaultQueryOptions),
updateQueryArgumentEffect.of(queryArgument),
updateQueryArgumentTypeEffect.of(queryArgumentType)
]
});