Categories
Mastering Development

How to remove quotes for json keys in json string using regex in jq

Trying to convert json payload to graphql and having some troubles.
I need to convert string like

"{
  \"entity\":{
    \"id\":\"7fbe7e65-0f01-4934-a2a9-dcc6d81a5b95\",
    \"type\":\"Products\",
    \"status\":\"pending\",
    \"services\":[
      {
        \"id\":\"1e05737e-754b-4d19-b872-5a0135d99cf4\",
        \"type\":\"Services\",
        \"status\":\"active\"
      },{
        \"id\":\"2238fe75-3d1a-4768-8464-be7d48037215\",
        \"type\":\"Services\",
        \"status\":\"active\"
      }
    ]
  }
}"

to string where no quotes for keys:

"{
  entity:{
    id:\"7fbe7e65-0f01-4934-a2a9-dcc6d81a5b95\",
    type:\"Products\",
    status:\"pending\",
    services:[
      {
        id:\"1e05737e-754b-4d19-b872-5a0135d99cf4\",
        type:\"Services\",
        status:\"active\"
      },{
        id:\"2238fe75-3d1a-4768-8464-be7d48037215\",
        type:\"Services\",
        status:\"active\"
      }
    ]
  }
}"

I managed to replace only all quotes but how can I remove quotes only for keys?
Please note that I have added \n here just for better understanding. Normally I got the json as a string without \n.

Leave a Reply

Your email address will not be published. Required fields are marked *