New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-dot-notation-converter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-dot-notation-converter

Json dot notation converter

  • 0.5.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

[ JDN ]

Json DOT Notation Converter

Convert JSON / OBJECT by instructions. Instructions are string dot notation directives.

Example

Input:
{
  items: [{
    a: 'London',
    b: '1500',
    nested: {
      a: 'John doe',
      b: '28',
      c: 'UK',
    }
  }]
}
Instructions:
  [
    ['items[].a', 'items[].city'],
    ['items[].b', 'items[].price'],
    ['items[].nested', 'items[].user']
  ],
  [
    ['items[].user.a', 'items[].user.name'],
    ['items[].user.b', 'items[].user.age'],
    ['items[].user.c', 'items[].country'],
  ]
]
Output:
{
  "items": [{
    "city": "London",
    "price": "1500",
    "country": "UK",
    "user": {
      "name": "John doe",
      "age": "28"
    }
  }]
}

Examples and explanation

Rename name into surname

input: { name: 'A' }
instruction: ['data.name', 'data.surname']
output: { surname: 'A' }

inputinstructionoutput
{ name: 'A' }['name', 'surname']{ surname: 'A' }
Copy name into surname

Copy is a special attribute that can be added to instruction.

inputinstructionoutput
{ name: 'A' }['name', 'surname', ['copy']]{ name: 'A', surname: 'A' }
Move price from object to parent
inputinstructionoutput
{ name: 'A', car: { type: 'Mazda', price: 100 }}['car.price', 'price']{ name: 'A', price: 100, car: { type: 'Mazda' }}
Move price from object to not existing object
inputinstructionoutput
{ name: 'A', car: { type: 'Mazda', price: 100 }}['car.price', 'price.mazda']{ name: 'A', car: { type: 'Mazda' }, mazda: { price: 100 }}
Move all price from array object
inputinstructionoutput
{ name: 'A', cars: [{ type: 'Mazda', price: 100 }]}['cars[].price', 'prices[].price']{ name: 'A', cars: [{ type: 'Mazda' }], prices: [{ price: 100 }]}

FAQs

Package last updated on 30 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc