Removing '\' in JQ Transform

47 views Asked by At

I'm trying to use JQ Transform (https://jqplay.org/) on a JSON object, which I would like to store as string, but it always replaces " with \"

How can I get rid of this \ ?

Input JSON: {"intents":[],"entities":[]}

JQ filter: .|tostring

Output JSON: {\"intents\":[],\"entities\":[]}

I know I would get desired result using Raw Output, but I cannot use it. I can only modify .|tostring filter. Please help.

1

There are 1 answers

0
Mat Ford On

You can use gsub to filter the string.

Input json:

{"intents":[],"entities":[]}

jq filter:

jq '.|tostring|gsub("\\\"";"")'

Output json:

"{intents:[],entities:[]}"