JSON Key Lookup

Hi there,

Curious if anyone has any good suggestions on the below problem. We are trying to get the keys from a JSON array object. The keys unfortunately are dates and are dynamic. For example, the below works fine, but it's hard-coding "09/03/2017". Any way to get all the keys from the object properly? Worth noting that index(local!list, 1) does not work in the below case.
=with(
local!json: "{
""09/03/2017"": {
""total"": 5
},
""10/03/2017"": {
""total"": 5
}
}",
local!list: a!fromJson(local!json),
index(local!list, "09/03/2017")
)

OriginalPostID-268859

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    I was going to suggest using a!jsonPath, but it appears it's impossible to get the key names in that manner. Arguably the JSON here, whilst syntactically valid, isn't really logically valid. However, it is possible to extract the keys from the JSON using a regex, and then loop over them - but it does require the regex plugin:

    = with(
    local!json: "{
    ""09/03/2017"": {
    ""total"": 5
    },
    ""10/03/2017"": {
    ""total"": 5
    }
    }",
    apply(
    fn!index(
    a!fromJson(
    local!json
    ),
    _,
    null
    ),
    fn!regexallmatches(
    "([0-9]{2}\\/[0-9]{2}\\/[0-9]{4})",
    local!json
    )
    )
    )
Reply
  • 0
    Certified Lead Developer
    I was going to suggest using a!jsonPath, but it appears it's impossible to get the key names in that manner. Arguably the JSON here, whilst syntactically valid, isn't really logically valid. However, it is possible to extract the keys from the JSON using a regex, and then loop over them - but it does require the regex plugin:

    = with(
    local!json: "{
    ""09/03/2017"": {
    ""total"": 5
    },
    ""10/03/2017"": {
    ""total"": 5
    }
    }",
    apply(
    fn!index(
    a!fromJson(
    local!json
    ),
    _,
    null
    ),
    fn!regexallmatches(
    "([0-9]{2}\\/[0-9]{2}\\/[0-9]{4})",
    local!json
    )
    )
    )
Children
No Data