22 Mar 2023 10:12 AM
Hi,
Can we Unescape JSON content to JSON object with DPL?
The reason for this is we want to parse log like this
{"content": "{\"level\":\"info\"}"}
to this
{"content": "{\"level\":\"info\"}"
"level":"info"
}
and if possible to do this dynamically without manual input of the field name and able to append the filed to become something like "xxx_level" so we can reuse in other log
{"content": "{\"level\":\"info\"}"
"xxx_level":"info"
}
08 Jun 2023 03:25 PM
@Ardhi were you able to get a solution to this?
09 Jun 2023 03:07 AM
unfortunately not, only able to do it manually one by one (not dynamic) to extract json field
09 Jun 2023 08:56 AM - edited 09 Jun 2023 08:57 AM
It would be possible to parse selected members with the specified matcher from JSON objects. In your example you could try a pattern like this:
json{json:"content"}:d
To test it out, you could try to execute the following query with mocked data:
data record(line = """{"content": "{\"level\":\"info\"}"}""")
| parse line, """json{json:"content"}:d"""
Maybe this would get you closer to what you're trying to achieve?