Ad Widget

Collapse

JSON Path string to number

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • markfree
    Senior Member
    • Apr 2019
    • 868

    #1

    JSON Path string to number

    Using preprocessing, I'm trying to read some JSON data from a service and it is returning me a string instead of a number.

    The JSON is similar to this:
    Code:
    {
    "nodes": {
    "rHhmEKJNSMmpcV9p5my2CQ": {
    "timestamp": null,
    "name": "",
    "transport_address": "",
    "host": "",
    "ip": "",
    "roles": null,
    "attributes": {},
    "indices": {},
    "os": {
    "timestamp": 1655814297289,
    "cpu": {
    "percent": 19,
    "load_average": {
    "1m": 2.08,
    "5m": 2.16,
    "15m": 2.14
    }
    }
    }
    }
    }
    }
    I want to extract the load_average for 1m, so I'm using this JSONPath:
    Code:
    $.nodes.*.os.cpu.load_average.1m
    With this path I can reach the correct value, but it happens to be a string.
    Instead of receiving 2.08 number, I'm getting [2.08] string (with brackets).
    Therefore, my item gets unsupported.

    Is there a way to convert this string to a number using JSONPath?
  • Answer selected by markfree at 24-06-2022, 04:12.
    cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    There was a similar thing just recently...
    use "$.nodes.*.os.cpu.load_average.1m.first()"

    Comment

    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #2
      There was a similar thing just recently...
      use "$.nodes.*.os.cpu.load_average.1m.first()"

      Comment

      Working...