Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
jsonjoy-com/json-pointer
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Fast implementation ofJSON Pointer (RFC 6901)specification in TypeScript.
Can find a value in a JSON object using three methods: (1) JSON Pointer string,(2) array of steps, or (3) a pre-compiled function.
Find the value in a JSON document at some specific location.
import{findByPointer}from'@jsonjoy.com/json-pointer';constdoc={foo:{bar:123,},};constres=findByPointer(doc,'/foo/bar');
Alternatively, you can specify an array of steps, such as['foo', 'bar']. Or,use theparseJsonPointer function to convert a JSON Pointer string to an array.
import{find,parseJsonPointer}from'@jsonjoy.com/json-pointer';constdoc={foo:{bar:123,},};constpath=parseJsonPointer('/foo/bar');constref=find(doc,path);console.log(ref);// { val: 123, obj: { bar: 123 }, key: 'bar'}
If you know the path in advance, you can compile a function that will find thevalue at that location, it will work few times faster than the previous methods.
import{$$find}from'@jsonjoy.com/json-pointer/lib/codegen';constdoc={foo:{bar:123,},};constfinder=$$find(['foo','bar']);constres=finder(doc);
Convert JSON Pointer to path array and back.
import{parseJsonPointer}from'@jsonjoy.com/json-pointer';console.log(parseJsonPointer('/f~0o~1o/bar/1/baz'));// [ 'f~o/o', 'bar', '1', 'baz' ]console.log(formatJsonPointer(['f~o/o','bar','1','baz']));// /f~0o~1o/bar/1/baz
Decode and encode a single step of JSON Pointer.
console.log(unescapeComponent('~0~1'));// ~/console.log(escapeComponent('~/'));// ~0~1
About
Fast JSON Pointer implementation in JavaScript
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.