Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fast JSON Pointer implementation in JavaScript

NotificationsYou must be signed in to change notification settings

jsonjoy-com/json-pointer

Repository files navigation

Fast implementation ofJSON Pointer (RFC 6901)specification in TypeScript.

Usage

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.

Examples

Find the value in a JSON document at some specific location.

Find by JSON Pointer string

import{findByPointer}from'@jsonjoy.com/json-pointer';constdoc={foo:{bar:123,},};constres=findByPointer(doc,'/foo/bar');

Find by path array

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'}

Pre-compiled function

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);

Low-level API

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

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp