Skip to content

Support parsing JSON object wrapped as a raw JSON string #418

Description

@arsalanyavari

Hi,

It would be very useful to have an option/flag in json_exporter to parse responses where the body is a raw JSON string, but the string content itself is a JSON object .

For example, this works fine when the response is a normal JSON object:

{"latest_datapoint_creation_height":1737045, "latest_datapoint":3134069212}

path: '{ .latest_datapoint_creation_height }'

But in my case, the endpoint returns something like this instead:

"{\"latest_datapoint_creation_height\":1737045,\"latest_datapoint\":3134069212}"

So the response is valid JSON, but the root value is a string, and that string contains a serialized JSON object.

Note

This issue is particularly relevant for legacy systems or APIs that might return stringified JSON due to historical reasons, simplicity in storage, or specific data transfer protocols. In such systems, it would be beneficial for json_exporter to support the parsing of these types of responses.

Could you add a flag to make json_exporter decode that inner JSON string before applying JSONPath?

Something like parse_embedded_json: true; Example Idea:

modules:
  default:
    metrics:
      - name: ergo_oracle_height
        path: '{ .latest_datapoint_creation_height }'
        parse_embedded_json: true

Expected behavior:

  1. Parse the response body as JSON
  2. If the root value is a string and this flag is enabled, parse that string again as JSON
  3. Apply JSONPath on the decoded inner object

This would help with endpoints that return JSON objects wrapped as raw JSON strings, without needing an extra preprocessing service.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions