Using `jq`:
```lang-none
$ jq '.topics[0].topic |= "test_1"' file.json
{
"topics": [
{
"topic": "test_1"
}
],
"version": 1
}
```
This reads the JSON document and modifies the value of the `topic` entry of the first element of the array `topics` to `test_1`.
If you have your value in a variable:
```lang-none
$ val='Some value with "double quotes"'
$ jq --arg string "$val" '.topics[0].topic |= $string' file.json
{
"topics": [
{
"topic": "Some value with \"double quotes\""
}
],
"version": 1
}
```
---
Using Perl:
```lang-none
$ perl -MJSON -00 -e '$h=decode_json(<>); $h->{topics}[0]{topic}="test_1"; print encode_json($h), "\n"' file.json
{"topics":[{"topic":"test_1"}],"version":1}
```
With a variable:
```lang-none
$ val='Some value with "double quotes"'
$ string=$val perl -MJSON -00 -e '$h=decode_json(<>); $h->{topics}[0]{topic}=$ENV{"string"}; print encode_json($h), "\n"' file.json
{"topics":[{"topic":"Some value with \"double quotes\""}],"version":1}
```
Both of these uses the Perl `JSON` module to decode the JSON document, change the value that needs changing, and then output the re-encoded data structure.
For the second piece of code, the value to be inserted is passed as an environment variable, `string`, into the Perl code. This is due to reading the JSON document from file in "slurp" mode with `-00`.