JSON to Shell/Bash Converter
Flatten JSON into bash variables you can source
JSON Input
Shell/Bash Output
What does the JSON to Shell converter do?
Reading JSON in a shell script usually means jq calls scattered everywhere. When the data is fixed (a deploy config, a list of regions, test values), it's often simpler to turn it into plain variables once. Paste JSON here and every value becomes a bash variable named after its path: {"subscriber": {"plan": "Unlimited 5G"}} becomes DATA_SUBSCRIBER_PLAN='Unlimited 5G'. camelCase keys are split into words, so billingCycle becomes BILLING_CYCLE.
Every string is written in single quotes, so $5, backticks, $(whoami) and backslashes are stored literally and never run. A single quote inside a value is written as '\'', the standard trick. A flat list such as ["international", "hotspot"] becomes a real bash array, DATA_SUBSCRIBER_ADD_ONS=('international' 'hotspot'). Lists that contain objects get a _COUNT variable plus numbered names (DATA_DEVICES_0_TYPE), because bash has no nested arrays.
Numbers and booleans are written bare (45.2, true), and large integers keep every digit. null becomes an empty string. If two keys flatten to the same name, like user-id and user_id, the second gets a number on the end instead of overwriting the first. The variables are not exported; add export, or wrap the source in set -a / set +a, if child processes need them. The output is checked with bash -n and by sourcing it. It all runs in your browser.
How to use it
The script updates as you type.
Paste JSON
Paste into the Input panel, Upload a .json or .txt file, or click Sample. Example input:
{"subscriberId":"SUB-1001","plan":"Unlimited 5G","dataUsage":45.2,"status":"active"}Variable Prefix sets the first part of every name (DATA by default); it's upper-cased and anything other than letters, digits and underscores becomes an underscore. Check odd input with the JSON Validator first.
Check the variables
The Output panel shows the script, one assignment per line, after a short header explaining the naming.
Copy or download
Copy it or Download data.sh, then source ./data.sh and use "$DATA_SUBSCRIBER_PLAN" or "${DATA_SUBSCRIBER_ADD_ONS[@]}".
Where this saves time
Deploy scripts
Turn a JSON deploy config (regions, instance sizes, image tags) into variables your bash deploy script sources, without adding jq to the build image.
CI jobs
Commit a generated variables file next to the pipeline and source it in each step, so every job reads the same values the same way.
Looping over a list
A JSON list of hostnames becomes a bash array you can loop over with for h in "${DATA_HOSTS[@]}"; do ... done.
Seeing a payload flat
Flattening a nested response into path-named variables is a quick way to see every leaf value at once, which helps when you're writing jq filters for it later.
Common Questions
Is the output safe to source?
Yes. Every string is single-quoted, so nothing inside it is expanded or executed, even values like $(rm -rf /). Names are built only from letters, digits and underscores.
Does it work in sh or zsh?
Scalar assignments work in any POSIX shell. The NAME=(...) array lines need bash, zsh or ksh, which is why the file starts with #!/usr/bin/env bash. Note that zsh arrays start at index 1.
Why aren't the variables exported?
Most scripts only need them in the current shell. Exporting everything would leak them into every child process. Add export to the lines you need, or use set -a before sourcing.
How are null and empty values handled?
null becomes an empty string (NAME=''), an empty list becomes NAME=(), and an empty object produces no variables at all.
Is my JSON uploaded?
No. The script is generated by JavaScript in your browser and nothing is sent to a server. Input is capped at 256 KB.
Other JSON Tools You Might Need
Need the data in PowerShell or another language instead?