Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-23415

Problem with JSONPATH (order)

XMLWordPrintable

    • Icon: Problem report Problem report
    • Resolution: Won't fix
    • Icon: Trivial Trivial
    • None
    • 6.4.6
    • None

      Steps to reproduce:
      I have the following json (I removed most of the fields for readability):
       

      { "20210926-064312-17958471": { "end_time": "2021-09-26T06:46:31.050Z" }, "20211102-092447-18455184": { "end_time": "2021-11-02T09:24:55.219Z" }, "20211102-092511-18455184": { "end_time": "2021-11-02T09:32:31.410Z" }, "20211102-094002-18455184": { "end_time": "2021-11-02T09:41:49.262Z" }, "20211102-095853-18455184": { "end_time": "2021-11-03T05:26:11.849Z" }, "20230823-030009-21784236": { "end_time": "2023-08-23T03:20:09.069Z" }, "20230824-030009-21784236": { "end_time": "2023-08-24T03:20:00.125Z" }, "20230825-030009-21784236": { "end_time": "2023-08-25T03:20:05.900Z" }, "20230826-030009-21784236": { "end_time": "2023-08-26T03:20:17.920Z" }, "20230827-030009-21784236": { "end_time": "2023-08-27T03:20:09.346Z" }, "20230828-030008-21784236": { "end_time": "2023-08-28T03:20:11.834Z" }, "20230829-030009-21784236": { "end_time": "2023-08-29T03:20:05.929Z" }, "20230830-030008-21784236": { "end_time": "2023-08-30T03:01:03.968Z" }, "20230831-030009-21784236": { "end_time": "2023-08-31T03:20:03.778Z" }, "20230901-030008-21784236": { "end_time": "2023-09-01T03:20:07.291Z" }, "20230902-030009-21784236": { "end_time": "2023-09-02T03:20:09.610Z" }, "20230903-030009-21784236": { "end_time": "2023-09-03T03:19:59.642Z" }, "20230904-030008-21784236": { "end_time": "2023-09-04T03:20:09.436Z" }, "20230905-030008-21784236": { "end_time": "2023-09-05T03:20:02.472Z" }, "20230906-030009-21784236": { "end_time": "2023-09-06T03:20:09.999Z" }, "20230907-030009-21784236": { "end_time": "2023-09-07T03:20:15.548Z" }, "20230908-030009-21784236": { "end_time": "2023-09-08T03:20:18.067Z" }, "20230909-030008-21784236": { "end_time": "2023-09-09T03:20:22.196Z" }, "20230910-030009-21784236": { "end_time": "2023-09-10T03:20:10.417Z" }, "20230911-030010-21784236": { "end_time": "2023-09-11T03:20:08.472Z" }, "20230912-030010-21784236": { "end_time": "2023-09-12T03:20:16.935Z" }, "20230913-030009-21784236": { "end_time": "2023-09-13T03:20:10.593Z" }, "20230914-030009-21784236": { "end_time": "2023-09-14T03:20:04.175Z" } }

       
       
      These are the dates of backups made. I want to extract the last date (last field from json). Due to the structure of the received json, I wanted to do the following:
      1. JSONPATH: $..end_time
      2. JSONPATH: $[-1:]
      Result:
      The problem occurs in the first step ($..end_time). Unfortunately I get the following output:

      [
          "2023-08-27T03:20:09.346Z",
          "2023-09-07T03:20:15.548Z",
          "2023-08-28T03:20:11.834Z",
          "2023-09-12T03:20:16.935Z",
          "2021-11-02T09:24:55.219Z",
          "2023-09-11T03:20:08.472Z",
          "2023-09-08T03:20:18.067Z",
          "2023-09-10T03:20:10.417Z",
          "2023-09-05T03:20:02.472Z",
          "2023-08-24T03:20:00.125Z",
          "2021-11-03T05:26:11.849Z",
          "2023-09-09T03:20:22.196Z",
          "2023-09-03T03:19:59.642Z",
          "2023-08-31T03:20:03.778Z",
          "2021-09-26T06:46:31.050Z",
          "2023-08-25T03:20:05.900Z",
          "2023-08-23T03:20:09.069Z",
          "2023-09-04T03:20:09.436Z",
          "2023-09-06T03:20:09.999Z",
          "2023-09-01T03:20:07.291Z",
          "2021-11-02T09:41:49.262Z",
          "2021-11-02T09:32:31.410Z",
          "2023-09-13T03:20:10.593Z",
          "2023-08-26T03:20:17.920Z",
          "2023-09-14T03:20:04.175Z",
          "2023-09-02T03:20:09.610Z",
          "2023-08-29T03:20:05.929Z",
          "2023-08-30T03:01:03.968Z"
      ]

      Expected:
      Desired output (checked on https://jsonpath.com/):

      [
        "2021-09-26T06:46:31.050Z",
        "2021-11-02T09:24:55.219Z",
        "2021-11-02T09:32:31.410Z",
        "2021-11-02T09:41:49.262Z",
        "2021-11-03T05:26:11.849Z",
        "2023-08-23T03:20:09.069Z",
        "2023-08-24T03:20:00.125Z",
        "2023-08-25T03:20:05.900Z",
        "2023-08-26T03:20:17.920Z",
        "2023-08-27T03:20:09.346Z",
        "2023-08-28T03:20:11.834Z",
        "2023-08-29T03:20:05.929Z",
        "2023-08-30T03:01:03.968Z",
        "2023-08-31T03:20:03.778Z",
        "2023-09-01T03:20:07.291Z",
        "2023-09-02T03:20:09.610Z",
        "2023-09-03T03:19:59.642Z",
        "2023-09-04T03:20:09.436Z",
        "2023-09-05T03:20:02.472Z",
        "2023-09-06T03:20:09.999Z",
        "2023-09-07T03:20:15.548Z",
        "2023-09-08T03:20:18.067Z",
        "2023-09-09T03:20:22.196Z",
        "2023-09-10T03:20:10.417Z",
        "2023-09-11T03:20:08.472Z",
        "2023-09-12T03:20:16.935Z",
        "2023-09-13T03:20:10.593Z",
        "2023-09-14T03:20:04.175Z"
      ]

      The order of dates in the output  is all mixed up. This change generally occurs when "JSONPATH" preprocessing is used and returns more than one "field". Is it possible to change the JSONPATH functionality so that it would always return the results in order of appearance in the input? 

            zabbix.support Zabbix Support Team
            aprzybylski Albert Przybylski
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: