Skip to content

Iterate through child array with labels in parent? #168

Closed
@liam-hogan

Description

@liam-hogan

Hi all, I am thoroughly enjoying this tool, but I have reached a weird obstacle regarding parsing through data.

Here's the issue:
I have a JSON file that is structured like so:

{
    "title": "JSON data",
    "timestart": "07/21/2022 13:53:20",
    "timeend": "07/21/2022 13:55:00",
    "table": [
        {array: value,
          of: value,
          items: value},
        {array: value,
          of: value,
          items: value},
        {array: value,
          of: value,
          items: value}]
}

I had to remove important data for this example, but this should suffice.

This works fine when I set the config.yml to something like this:

headers:
  MyHeader: MyHeaderValue
modules:
  default:
    metrics:
    - name: JSON_DATA
      type: object
      help: JSON_DATA test
      path: '{.table[*]}'
      labels:
        id: '{.array}'
      values:
        of: '{.of}'
        items: '{.items}'

However, if I wish to use any of the parent nodes (title, timestart, timeend) in my labels as well as a label from the underlying table array, this becomes difficult. I understand that setting the path as a child node makes "looking up" to the parent impossible, so I thought I could traverse down:

headers:
  MyHeader: MyHeaderValue
modules:
  default:
    metrics:
    - name: JSON_DATA
      type: object
      help: JSON_DATA test
      path: '{$}'
      labels:
        id: '{.table[*].array}'
        timestart: '{.timestart}'
      values:
        of: '{.table[*].of}'
        items: '{.table[*].items}'

This does not work. I have some issues getting this to work properly, and it's definitely in part to my inexperience with JSONPath. I have been able to get an error where the data is ingested, but it is done in a way that instead of having one metric per instance, it gets every instance of that metric (causing an error).

Does anyone have suggestions on how to go about traversing and pairing the elements from the parents with the elements from the child array?

Also, I think the timestart is failing due to how the timestamp is formatted. Based on this documentation as well as the guide found here, I see the need for an object type, but I cannot find any reference for these object types. Does anyone have any information regarding this?

Thank you,
Liam Hogan

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