If your json format is in one-line then the following should work:
sed -i 's/"\([^"]*\)":/"x_\1":/g' json_file.json
If your json format looks like this:
{
"key_1": 1,
"key_2": "v2",
"key_3": 3
}
You could use the sed command above but you also can use the following sed which is a little easier:
sed -i 's/"\(.*\)":/"x_\1":/' json_file.json
Note: The solution above works well if you just have numbers or strings that don't have the following pattern:
{ "key_1": "\"Sale\": foobar" }
// Or
{ "\"key_1\"": "\"Sale\": foobar" } // I think this case is less common
So the best way to edit the keys correctly is by using the roaima's answer.
I tried another possible solution with sed (but I'm not sure if there are other cases where it might fail).
If your json file looks like this:
{"key_1": "\"Sale\": foobar", "key_2": "\"3\":", "key_3": 56}
// Or maybe
{"key_1": "\"Sale:sale\": foobar", "key_2": "\"3\":", "key_3": 56}
you can try using:
sed -i 's/"\([^"\][^"\]*\)":/"x_\1":/g' json_file.json
However the command above will fail if the json file looks like this:
{"\"key_1\"": "\"Sale:\": foobar", "key_2": "\"3\":", "key_3": 56}
// If the json keys have \"somekey\" as their keys then the sed command will fail.
// So using sed for this task might be a little tricky for avoiding these problems.