Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 612

Convert string to json in jq [duplicate]

$
0
0

Background

I have a json file that contains a string of json within an object:

{"requestType": "POST","response": {"size": 78,"text": "{\"recordID\":123, \"title\":\"Hello World\", \"content\":\"Lorem ipsum...\"}"    }}

I need to interperet the contents of the .response.text string as json using the json command line interpereter, jq.

When I run this command:

jq '.response.text | @json'

Output: "\"{\\\"recordID\\\":123, \\\"title\\\":\\\"Hello World\\\", \\\"content\\\":\\\"Lorem ipsum...\\\"}\""

I get some weird escaped json string instead of json that I can access via something like this: .response.text | @json | .recordID.

I realize that the @json function will take json and output a json escaped string, so there must be another way, but @text doesn't seem to do anything.

Question

Is there some way to convert a string of escaped json to actual json that I can parse with a command such as this: jq '.response.text | @json | .title' and get this output: "Hello World"?


Viewing all articles
Browse latest Browse all 612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>