Skip to content

Can't unmarshal -Infinity #46

@mngan

Description

@mngan

When trying to unmarshall the output of show interfaces transceiver dom thresholds, you sometimes can come across a channel value with -Infinity. This causes the JSON decoder to fail with an error like this:

interface-diagnostics: invalid character 'I' in numeric literal"

The JSON object in question looks like this:

{
  "interfaces": {
    "Ethernet54/1": {
      "updateTime": 1628733658.605624,
      "displayName": "Ethernet54/1",
      "parameters": {
        "txPower": {
          "channels": {
            "1": -Infinity
          },
          "threshold": {},
          "unit": "dBm"
        },
        "temperature": {
          "channels": {
            "-": 29.703125
          },
          "threshold": {
            "highWarn": 70.0,
            "lowWarn": 0.0,
            "highAlarm": 75.0,
            "lowAlarm": -5.0
          },
          "unit": "C"
        },
        "txBias": {
          "channels": {
            "1": 0.0
          },
          "threshold": {
            "highWarn": 0.0,
            "lowWarn": 0.0,
            "highAlarm": 0.0,
            "lowAlarm": 0.0
          },
          "unit": "mA"
        },
        "rxPower": {
          "channels": {
            "1": -30.0
          },
          "threshold": {},
          "unit": "dBm"
        },
        "voltage": {
          "channels": {
            "-": 3.3201
          },
          "threshold": {
            "highWarn": 3.45,
            "lowWarn": 3.1500000000000004,
            "highAlarm": 3.8000000000000003,
            "lowAlarm": 2.8400000000000003
          },
          "unit": "V"
        }
      },
      "vendorSn": "XXXXXX",
      "mediaType": "40GBASE-SR4"
    }
}

It seems that -Infinity isn't valid JSON, so it isn't supported by the JSON parser. So what is the way to handle this so you can at least skip over this value and still get the rest of the valid data back?

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