Ad Widget

Collapse

Creating an item prototype based on the existence of a JSON component

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mdella
    Junior Member
    • Apr 2024
    • 8

    #1

    Creating an item prototype based on the existence of a JSON component

    I want to create a prototype ONLY if a JSON component exists, otherwise skip itI'm working with a JSON data set that looks generally like the following:
    Code:
    [
      {
        "uuid": "f80cd686-f4d3-4cb0-b7b1-ba8e9fc3b22c",
        "hw_address": [
          {
            "ipv4": "10.55.37.27"
          }
        ]
      },
      {
        "uuid": "181f1f77-81fe-4f6c-b2c7-0b3d4da5a0b5",
        "hw_address":[
          {
            "ipv4": "10.55.37.28",
            "ipv6": "2001:db8:0:1::1"
          }
        ]
      }
    ]
    I've been successful in pulling in the $.uuid and creating a prototype on that. I want to create another prototype on $.hw_address[*].ipv4 and another one on $.hw_address[*].ipv6 however if the field isn't there, how to NOT create the prototype? Right now I get the following error type (ignore the mismatches to above, I just copied from live data):

    Code:
    Preprocessing failed for: {<JSON HERE>}
    1. Failed: cannot extract value from json by path "$..[?(@.uuid == 'f80cd686-f4d3-4cb0-b7b1-ba8e9fc3b22c')].hw_address[*].ipv6": no data matches the specified path
    If I define it, it creates the prototype but then fails with the above error. I'm trying to figure out how to conditionally create the prototype based on the presence of the value. Or at least silently fail if it doesn't

    Marcos
Working...