0.0.6 • Published 9 years ago

json-transfer v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
9 years ago

json-transfer

npm version Build Status Coverage Status

  • use path to update json

  • support wildcard *

install

   npm install json-transfer --save

usage

  • parameter: jsonTrans(json={}, rules=[])

    • json: the object you want to update, can be null;
    • rules: use rule in pairs mode, [jsonPath, value]], like:
      [['a.c', 0], ['a.b.d', 5]]
      - jsonPath: 'a.b.c', 'a.0.k', '', 'a.*.d'
      - value: can be any value
  • example

   const jsonTrans = require('json-transfer');
   let json = jsonTrans({
      errno: 0,
      data: [{
        id: 1,
        name: 'kino'
      },{
        id: 2,
        name: 'lee'
      }]
    }, [
        ['data.*.id', '3'],
        ['data.2.name', 'xuan']
    ]);

test

   npm test
0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago