jo
Create JSON objects from command-line arguments
TLDR
View documentation for the original command
SYNOPSIS
jo [options] [key=value ...]
jo -a [options] [value ...]
PARAMETERS
-a
Create a JSON array instead of an object.
-p
Pretty-print the JSON output for readability.
-s
Force string interpretation for the following values, overriding automatic type detection.
-n
Force null interpretation for the following values.
-b
Force boolean interpretation for the following values (e.g., 'true', 'false').
-i
Force integer interpretation for the following values.
-F file
Read content from file and embed it as a JSON string value.
-L file
Read content from file and embed it as a literal (unescaped) JSON value. Use with caution.
-e
Escape forward slashes (/) in string values.
-u
Unbuffered output; flush after each write.
-B
Print output to standard error instead of standard output.
-V
Display version information and exit.
-h
Display a help message and exit.
--
Marks the end of options, allowing arguments that start with - to be treated as keys or values.
DESCRIPTION
jo is a lightweight command-line utility designed to simplify the creation of JSON objects and arrays directly from shell arguments. It automates the often tedious process of correctly quoting, escaping, and formatting JSON data, making it ideal for shell scripting and rapid prototyping. jo intelligently infers data types, distinguishing between strings, numbers, booleans (true/false), and null values. It supports various ways to build complex structures, including nesting objects and arrays, and embedding file contents. Its ease of use makes it a powerful companion to tools like curl for sending API requests or jq for parsing and manipulating JSON, streamlining workflows where JSON data needs to be programmatically generated.
CAVEATS
jo is a third-party utility and is not part of the standard GNU core utilities; it must be installed separately (e.g., via a package manager like apt, dnf, or brew). Its automatic type inference, while convenient, may require explicit type forcing (e.g., with -s for strings) for ambiguous cases or specific formatting needs. Complex nested structures or very large inputs might be more efficiently handled by programming languages or libraries dedicated to JSON parsing/generation.
AUTOMATIC TYPE INFERENCE
jo intelligently attempts to determine the data type of each value provided (string, number, boolean, null) based on its format, simplifying command syntax and reducing manual effort.
HANDLING FILE CONTENT
Arguments like key=@filename or options like -F and -L allow embedding the content of files directly into JSON objects or arrays, useful for including large text blocks or pre-formatted JSON snippets.
NESTED STRUCTURES AND PIPING
Complex JSON structures can be built by nesting jo commands, where the output of one jo command is piped as an argument to another, enabling the creation of intricate objects and arrays dynamically.
HISTORY
jo was created by J. M. S. de Oliveira and first released around 2017. Its development aimed to provide a simple, robust, and intuitive way to generate JSON data directly from the shell, addressing the common need in scripting to construct well-formed JSON payloads without relying on more complex solutions like Python or Node.js scripts, or cumbersome string manipulations with sed and awk. It quickly gained popularity in the DevOps and scripting communities due to its efficiency and ease of integration.