Regex to find keys in JSON

grep, json, regex

Solution

You can try the following regex:

"([^"]+?)"\s*:

It will match any word character that may be between quotes(`" "`) succeed by a `:` (ignoring whitespaces).

Demo

Problem

I want to match keys in JSON string on linux shell grep. My objective is to remove JSON keys so that values would come out in CSV. Please help me with regex. I tried `"(.*?)":` ``` {"field1":"value1","field2":"value2"} ``` But above regex matches "field1": and then "value1","field2": So basically it shouldn't match groups containing comma. I know this should be done in python or java. But I want to avoid deployment of application on that specific server. Also internet access has been revoked from this server and many othe restrictions so I cannot install any new tools or commands. Is it possible?

Original source