Convert ctx to json or dictionary

If the context is sent as an alarm from opendistro, it looks like the following when received from a custom webhook (flask python). (when sent like {{ctx}})

b’{monitor={_id=, _version=1}, periodStart=2021-03-30T02:02:37.300Z}’

Is there a good way to get a json type or convert the received text into a python dictionary?

When I tried using python’s ‘json’ library, I had the following problem.

  1. The key is not enclosed in double quotation marks.
  2. Value is not enclosed in double quotation marks.
  3. There is an empty value.
  4. It is not in the form of ‘key:value’, but in the form of ‘key=value’.
  5. Value contains ‘:’.

You should be able to do this to return it in json format

{{#toJson}}ctx.results.0{{/toJson}}