I got a json data that some value I need is hiding in a string, but Im not sure is there a good way to pick it out.
the data I need is an url inside the string but conclude list and dict like:
data_2 = content["a"]["b"][0]["value"]
print(type(data_2))
>>>> <class 'str'>
print(data_2)
>>>> [{"id":"123","name":"John","url":"https://www.data.com/"}]
and I have to pick up the value of url.
strip() doesnt help btw, Im still trying.
the thing is kinda like
{"content":{"custom1":[
{
"value":"[{"id":"123","name":"John","url":"https://www.data.com/"}]"
}
]}}
>Solution :
Because you have shown data_2 to be String, the objects cannot be accessed directly. The json module can be used to first convert the String, then access first & only element of the list (a Dictionary( and then the url from the Dictionary.
import json
data_2 = '[{"id":"123","name":"John","url":"https://www.data.com/"}]'
data_3 = json.loads(data_2)
print(data_3[0]['url'])
gives