Announcement

Collapse
No announcement yet.

Parsing a nested JSON response for multiple values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Parsing a nested JSON response for multiple values

    I'm hoping someone here is able to help me.

    I have a video multiplexer that provides the following combined JSON output for input and output names, input selection and output power status to name a few.

    Is it possible in a single pass to get device names, the name of the input being sent to it and the power status?

    Input Name = inputs
    Output Name = outputs
    input number being directed to output = sstr
    Output powered on = orsense

    I have been able to pull any 1 of the items but what I would like is

    Device based on Outputs, so from below

    I would like to get the results to indicate that Device "Left" has Source "1" named "Pi TV 1" and is powered On. Likely a device with multiple features?

    Device "Left" - (outputs[1])
    Source "4" - (Split(JSON(input, "sstr"), ",")[1])[0]). ...used on the next line....
    named "Pi TV 4" (inputs[4])]
    powered On (if(orsense[1]))

    {
    "opol":["N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A"],
    "inputs": ["Pi TV 1","Pi TV 2","Pi TV 3","Pi TV 4","Mac","AppleTV","INPUT7","INPUT8"],
    "inputboards": ["N/A","N/A","N/A","N/A"],
    "outputboards": ["N/A","N/A","N/A","N/A"],
    "outputs": ["Left ","Center","Right","Tap","ATM","BarSeat","Cash","Barber"],
    "presetlist": ["Normal","Karaoke","StreamTV","All Pi 1","All Pi 2","All Pi 3","All Pi 4","All Mac"],
    "banks": ["Bank 1","Bank 2","Bank 3","Bank 4","Bank 5","Bank 6","Bank 7","Bank 8"],
    "matrixlock": 0,
    "fststr": "11111111",
    "hdcpstr": [00001000],
    "sstr": "1,2,3,4,4,2,3,4",
    "orsense": [1,1,1,0,0,0,1,1],
    "ohpd": [1,1,1,1,1,0,1,1],
    "omask": ["Off","Off","Off","Off","Off","Off","Off","Off"],
    "ohdcp": [0,0,0,0,0,0,0,0],
    "icd": ["8bit","-","-","-","10bit","-","-","-"],
    "ics": ["RGB","-","-","-","YUV","-","-","-"],
    "ihdcp": [0,0,0,0,1,0,0,0],
    "i3d": ["No","No","No","No","No","No","No","No"],
    "iactive": [1,0,0,0,1,0,0,0],
    "ivr": ["1080","-","-","-","1080","-","-","-"],
    "ivh": ["1920","-","-","-","1920","-","-","-"],
    "ipi": ["p","-","-","-","p","-","-","-"],
    "irr": ["60Hz","-","-","-","60Hz","-","-","-"]
    }

    #2
    I'm close to what I am trying to achieve, my real hurdle is using a return value from an expression to select an element from an expression

    Where X = Split(JSON(input, "sstr"), ",")[0]
    Desired Output = JSON(input, "inputs[X]")

    Any help would be appreciated, or is this even possible?

    Thanks

    Gerry

    Comment


      #3
      Gerald

      ​​​​​​​Big6 allows nestled expressions like you just did above

      Code:
      Split(JSON(input, "sstr"), ",")[0]
      Unfortunately the number in JSON list has to be a digit not expression.

      One way around it I can think of is to use If ... then ...else as outlined in the documentation here http://big6.ivanv.com/expressions/

      Here is an example (tested in Big6 sandbox) that goes to two levels but you can do as many levels as you wish just replace "end" with your next If... statement. This is tedious work and prone to typo errors but it is doable. Strongly recommended to use Big6 sandbox to test before any implementation.

      Code:
      ${ If( Split(JSON(input, "sstr"), ",")[0] = "1", JSON(input,"inputs[0]") , If( Split(JSON(input, "sstr"), ",")[0] = "2", JSON(input,"inputs[1]"), "end"))}
      The wrapper ${....} is needed for the sandbox. Remove it otherwise.

      Good luck

      Comment


        #4
        Thank you!

        That worked out, I'm amazed I've been able to extend a device into Homeseer that didn't have the means to do so in the first place!

        br,

        Gerry

        Comment

        Working...
        X