Structured Output
JSON Line
Emit One Object
JSON Lines store one JSON object per output line. Bash can build small JSON-shaped records from controlled values.
Program
Play the script to choose a result value and see one JSON-line record.
json_line.sh
#!/usr/bin/env bash
result=
name="smoke"
json="{\"name\":\"$name\",\"result\":\"$result\"}"
echo "$json"
#!/usr/bin/env bash
result=
name="smoke"
json="{\"name\":\"$name\",\"result\":\"$result\"}"
echo "$json"
JSON line
A JSON-line stream writes one JSON object per line.
controlled values
Small controlled values avoid shell-escaping problems in this introductory pattern.
machine output
Structured output is meant for another program as much as for a human reader.