Jo is a command-line utility that allows you to easily build JSON objects directly from your shell. It simplifies the process of creating structured JSON data without the need for complex scripting or manual formatting. Whether you're working with APIs, configuration files, or scripting tasks, Jo provides a straightforward way to generate JSON.
Jo excels at creating various JSON structures, including simple objects, nested objects, arrays, and combinations thereof. Its intuitive syntax makes it accessible for developers of all levels.
To create a simple JSON object, you can use the key-value pair syntax:
# jo
# Build JSON objects from the shell.
# Basic usage for creating a simple JSON object
jo name=John age=30
Jo supports creating nested JSON objects by assigning the output of another `jo` command to a key:
# Creating JSON objects with nested objects
jo person=$(jo name=Jane age=25) city=NewYork
You can create JSON arrays using the -a flag:
# Creating a JSON array
jo -a apple banana cherry
Combine objects and arrays seamlessly:
# Creating a JSON object with an array
jo fruits=$(jo -a apple banana cherry) type=food
For keys or values containing spaces or special characters, use quotes:
# Creating JSON objects with special characters or spaces
jo "name=John Doe" "occupation=Software Engineer"
Jo automatically handles numeric and boolean types:
# Creating JSON objects with numeric values
jo height=170 weight=60.5
# Creating JSON objects with boolean values
jo married=true
Represent JSON null values by assigning null:
# Handling JSON null values
jo name=null
Integrate shell variables directly into your JSON objects:
# Creating a JSON object from a shell variable
name=John
age=30
jo name=$name age=$age
# Combining static strings and variables in JSON
color=blue
jo item=car color=$color
Use the -p flag for formatted, human-readable JSON
output:
# Pretty printing JSON output
jo -- "-p" name=Emily age=40
Create complex structures with arrays of objects and deep nesting:
# Creating a JSON array with objects inside
jo -a $(jo name=Alice) $(jo name=Bob)
# JSON object with multiple nested levels
jo user=$(jo name=Chris details=$(jo [email protected] age=28)) status=active
Jo can also utilize environment variables:
# Using jo with environment variables
export COUNTRY=USA
jo country=$COUNTRY