I have a file with all type of brackets {}[]()
- nested, open and close appropriately. I would like to return the content within the matching square brackets after the string (text:
). The content of the file looks like this:
....
{
"text": [
{
"string1": ["hello", "world"],
"string2": ["foo", "bar"]
},
{
"string1": ["alpha", "beta"],
"string2": ["cat", "dog"]
}
],
"unwanted": [
{
"stuff": ["nonesense"]
}
]
}
.... and so on
I would like to return
{
"string1": ["hello", "world"],
"string2": ["foo", "bar"]
},
{
"string1": ["alpha", "beta"],
"string2": ["cat", "dog"]
}
The file is json
type and has similar structure throughout. I would like to return contents in the square brackets after text:
specifically.
text: [
and]
. Then again, if it's actually proper JSON, and the example is just off, then you should use a JSON parser. But that's something only you know, and you'll have to decide if heuristics are ok, or if you need an exact parse. – ilkkachu May 13 '22 at 16:45