json-tool

1.1.2 • Public • Published

json-tool

A simple command line tool for reading and editing json files.

Install via npm install -g json-tool

Use via json-tool [options] <file> <key>

File: JSON file to read/write. Key: Main json key to read/edit.

Reading JSON

-r, --read

To read the value of name from { "name": "Bob" }:

json-tool -r person.json name

Writing JSON

-w, --write <value>

To write 101 to the key age in { "name": "Bob" }:

json-tool -w 101 person.json age

Output to person.json is { "name": "Bob", "age": 101 }

Renaming/Changing JSON key

-c, --change <toKey>

To rename or change the key name in { "name": "Bob" } to first_name:

json-tool -c first_name person.json name

Output to person.json is { "first_name": "Bob" }

Deleting a JSON key

-d, --delete

To remove the age key from { "name": "Bob", "age": 101 }:

json-tool -d person.json age

Output to person.json is { "name": "Bob" }

Changing the spacing

-s, --spaces <spaces>

The default number is 4, if you want to change the spacing to 2 use -s 2.

Note: Currently this change is tied to editing the JSON, you will need to use this with -w, -c, or -d.

Using deep keys

If you want to read or modify deeper keys, you just need to use dot syntax for the <key> input.

e.g.

json-tool -w 101 team.json bob.age

json-tool -w 101 companies.json google.bob.age

Package Sidebar

Install

npm i json-tool

Weekly Downloads

80

Version

1.1.2

License

GPL-3.0

Last publish

Collaborators

  • digikid13