1.0.1 • Published 5 years ago

cmd-to-json v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

CircleCI npm.io Latest version

cmd-to-json

A simple CLI utility for creating JSONs from command line.

Installation

npm i -g cmd-to-json

Usage

Create JSON from command line by specifying properties and their values:

to-json name="John Doe" age=32 married=true

gives this output (formatted for better readability):

{
  "name": "John Doe",
  "age": 32,
  "married": true
}

Main use-case of the tool is calling APIs with curl from command line:

to-json userId=123 title="Post title" body="Post body..." | curl -X POST -d @- -H "Content-type: application/json" https://jsonplaceholder.typicode.com/posts

Nested objects

Nested structures can be created by using dots in property names:

to-json version=1 person.name="John" person.age=32

will yield:

{
  "version": 1,
  "person": {
    "name": "John",
    "age": 32
  }
}

Arrays are not yet supported.

Explicit formats

Numbers and booleans are recognized and formatted automatically. You may force a specific format like this:

to-json houseNumber:string=134 age:number=35

which will yield

{"houseNumber":"134","age":35}

Appending :string suppresses automatic formatting. :number and :boolean can be used for input validation (e.g. to-json age:number="foo" will throw an error).

###Full list of formats

FormatValid value examplesResulting property valueNote
number1, "1", 1.234, 1e21, 1, 1.234, 100Useful for validation.
booleantrue, false, TRUEtrue, false, trueDtto. Not case sensitive.
stringJohn, "John", 1, true"John", "John", "1", "true"Useful to suppress default formatting.
singlelinemore\nlines"more lines"Replaces sequences of newlines by a space.

Limitations

Currently there's no way to escape the special characters in property names (:, =, +, ., single _).

1.0.1

5 years ago

1.0.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago