Git Product home page Git Product logo

jsonuri's Introduction

JSON URI


Use URI path to get or set data.

show

Install

$ npm install jsonuri --save

Example Data:

{
    "menu": {
        "id": 123,
        "list": [0,1,2,3,4],
        "popup": {
            "menuitem": [
                {
                    "value": "New",
                    "onclick": "CreateNewDoc()"
                },
                {
                    "value": "Open",
                    "onclick": "OpenDoc()"
                },
                {
                    "value": "Close",
                    "onclick": "CloseDoc()"
                }
            ]
        }
    }
}

Methods:

get (data, path)

Get the value of the specified data for the path.

Example:

get(data, '/menu/id/');
//123

get(data, '/menu/popup/menuitem/0/value/');
//"New"

get(data, '/menu/popup/menuitem/0/value/../');
//{value: "New", onclick: "CreateNewDoc()"}

set (data, path, value)

Set the value of the specified data for the path.

Example:

set(data, '/menu/id/',789);
get(data, '/menu/id/');
//789

rm (data, path)

Remove the value of the specified data for the path.

Example:

rm(data, '/menu/id/');
get(data, '/menu/id/');
//undefined

mv (data, pathA, pathB, sequence)

Data A moved to target B before or after.

Example:

mv(data, '/menu/list/0', '/menu/list/3');
get(data, '/menu/list/');
//[1,2,3,0,4]


set(data, '/menu/list/',[0,1,2,3,4]);
mv(data, '/menu/list/0', '/menu/list/3', 'before');
get(data, '/menu/list/');
//[1,2,0,3,4]

swap (data, pathA, pathB)

Data swap in an array.

Example:

swap(data, '/menu/list/0', '/menu/list/4');
get(data, '/menu/list/');
//[4,1,2,3,0]

swap(data, '/menu/list/0', '/menu/list/4');
get(data, '/menu/list/');
//[4,1,2,3,0]

insert (data, pathA, value, direction)

Insert data into an array that is described in the path.

Example:

insert(data, '/menu/list/0', 9999, 'before');
//[9999,0,1,2,3,4]

up(data, path, gap)

down(data, path, gap)

walk(data, descentionFn, ascentionFn)

Traverse each data of each node and value.

Example:

walk({a:{a1:'x'}}, function(obj, key, raw, path){
  console.log(obj, key, raw, path)
})

// { a1: 'x' } 'a' { a: { a1: 'x' } } '/a/'
// x a1 { a1: 'x' } /a/a1/

normalizePath(path1, path2, ...)

Example:

normalizePath('a', 'b')  
// /a/b/

normalizePath(['a', 'b', '../'], 'c')
// /a/c/


jsonuri's People

Contributors

height avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.