GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  JO (1)

NAME

jo - JSON output from a shell

CONTENTS

Synopsis
Description
Examples
Options
Bugs
Return Codes
Availability
Credits
See Also
Author

SYNOPSIS

jo [-p] [-a] [-B] [-v] [-V] [word ...]

DESCRIPTION

I]jo] creates a JSON string on I]stdout] from I]word]s given it as arguments or read from I]stdin]. Without option C]-a] it generates an object whereby each I]word] is a C]key=value] (or C]key\@value]) pair with I]key] being the JSON object element and I]value] its value. I]jo] attempts to guess the type of I]value] in order to create number (using I]strtod(3)]), string, or null values in JSON.

I]jo] treats C]key\@value] specifically as boolean JSON elements: if the value begins with C]T], C]t], or the numeric value is greater than zero, the result is C]true], else C]false]. A missing or empty value behind the colon results in a C]null] JSON element.

I]jo] creates an array instead of an object when C]-a] is specified.

EXAMPLES

Create an object. Note how the incorrectly-formatted float value becomes a string:
C]
$ jo tst=1457081292 lat=12.3456 cc=FR badfloat=3.14159.26 name="JP Mens" nada= coffee\@T
{"tst":1457081292,"lat":12.3456,"cc":"FR","badfloat":"3.14159.26","name":"JP Mens","nada":null,"coffee":true}
]

Pretty-print an array with a list of files in the current directory:
C]
$ jo -p -a *
[
 "Makefile",
 "README.md",
 "jo.1",
 "jo.c",
 "jo.pandoc",
 "json.c",
 "json.h"
]
]

Create objects within objects; this works because if the first character of value is an open brace or a bracket we attempt to decode the remainder as JSON. Beware spaces in strings ...
C]
$ jo -p name=JP object=$(jo fruit=Orange hungry\@0 point=$(jo x=10 y=20 list=$(jo -a 1 2 3 4 5)) number=17) sunday\@0
{
 "name": "JP",
 "object": {
  "fruit": "Orange",
  "hungry": false,
  "point": {
   "x": 10,
   "y": 20,
   "list": [
    1,
    2,
    3,
    4,
    5
   ]
  },
  "number": 17
 },
 "sunday": false
}
]

Booleans as strings or as boolean (pay particular attention to I]switch]; the C]-B] option disables the default detection of the "C]true]" and "C]false]" strings):
C]
$ jo switch=true morning\@0
{"switch":true,"morning":false}

$ jo -B switch=true morning\@0 {"switch":"true","morning":false} ]

Elements (objects and arrays) can be nested. The following example nests an array called I]point] and an object named I]geo]:
C]
$ jo -p name=Jane point[]=1 point[]=2 geo[lat]=10 geo[lon]=20
{
   "name": "Jane",
   "point": [
      1,
      2
   ],
   "geo": {
      "lat": 10,
      "lon": 20
   }
}
]

Read element values from files: a value which starts with C]\@] is read in plain whereas if it begins with a C]%] it will be base64-encoded:
C]
$ jo program=jo authors=\@AUTHORS
{"program":"jo","authors":"Jan-Piet Mens <jpmens\@gmail.com>"}

$ jo filename=AUTHORS content=%AUTHORS {"filename":"AUTHORS","content":"SmFuLVBpZXQgTWVucyA8anBtZW5zQGdtYWlsLmNvbT4K"} ]

OPTIONS

I]jo] understands the following options.
-a Interpret the list of I]words] as array values and produce an array instead of an object.
-B By default I]jo] interprets the strings "C]true]" and "C]false]" as boolean elements C]true] and C]false] respectively. Disable with this option.
-p Pretty-print the JSON string on output instead of the terse one-line output it prints by default.
-v Show version and exit.
-V Show version as a JSON object and exit.

BUGS

Probably.

If a value given to I]jo] expands to empty in the shell, then I]jo] produces a C]null] in object mode, and might appear to hang in array mode; it is not hanging, rather it[aq]s reading I]stdin]. This is not a bug.

Numeric values are converted to numbers which can produce undesired results. If you quote a numeric value, I]jo] will make it a string. Compare the following:
C]
$ jo a=1.0
{"a":1}
$ jo a=\"1.0\"
{"a":"1.0"}
]

Omitting a closing bracket on a nested element causes a diagnostic message to print, but the output contains garbage anyway. This was designed thusly.

RETURN CODES

I]jo] exits with a code 0 on success and non-zero on failure after indicating what caused the failure.

AVAILABILITY

<http://github.com/jpmens/jo>

CREDITS

[bu] This program uses C]json.[ch]], by Joseph A. Adams.

SEE ALSO

[bu] <https://stedolan.github.io/jq/>
[bu] <https://github.com/micha/jsawk>
[bu] strtod(3)

AUTHOR

Jan-Piet Mens <http://jpmens.net>

Search for    or go to Top of page |  Section 1 |  Main Index


User Manuals JO (1)

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.