Question: I have a small script

```
ABC=100000
DFG=600000

JSON="[{"Address":"$ABC","Backup":false,"name":"$ABC:11011","port":6745,"targetId":"$DFG","weight":1}]"

echo $JSON

```

I get the output as

```
[{Address:$ABC,Backup:false,name:$ABC:11011,port:6745,targetId:$DFG,weight:1}]

```

can someone please help me in this case
T.I.A

Answer: 
Note that injecting the values of shell variables into JSON documents may result in broken JSON strings due to the lack of encoding special values. It would be better (more robust) to use a JSON-aware tool to create the JSON document and to insert the wanted values.

Using `jq` to compose the JSON document from a simple template:

```bash
ABC=100000
DFG=600000

jq -n \
    --arg Address  "$ABC" \
    --arg targetId "$DFG" \
    --arg name     "$ABC:11011" \
    '[ $ARGS.named + { Backup: false, port: 6745, weight: 1 } ]'

```

Output (use `jq` with `-c` to get "compact" output):

```json
[
  {
    "Address": "100000",
    "targetId": "600000",
    "name": "100000:11011",
    "Backup": false,
    "port": 6745,
    "weight": 1
  }
]

```

This creates an array consisting of a single element, a static object to which we add some named fields with values. The field names (keys) and their values are given using `--arg key value` repeatedly on the command line.

Since we're using `jq` to create the JSON document, this would still work if `ABC` held a value like `100 "My Road"` (i.e. with embedded quotes, or newlines, or tabs, etc.).
You can also use a here document to populate the variable with a JSON structure in expanded form that can be easier for people to read and maintain, and substitute shell variable values into the middle without a lot of backslashes to escape quote characters:

```
f_name=Sotto
l_name=Voce
JSON=$(cat - <<EOJSON
{
  "first_name": "${f_name}",
  "last_name": "${l_name}",
  "full_name": "${f_name} ${l_name}"
}
EOJSON
)

```

Then `echo "${JSON}"` or `echo "$JSON"` outputs:

```
{
  "first_name": "Sotto",
  "last_name": "Voce",
  "full_name": "Sotto Voce"
}

```

My personal style uses curly braces around variable names everywhere, but it's not required here. Using `$f_name` also works in this example.

I've come to think of here documents as another type of string quoting. Since single- or double-quotes aren't being used to quote the whole string, you don't usually need to escape them with backquotes.