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
    Here is an Appian implementation for your data model. Note that it could probably be cleaned up and it may not work for other data models! Also, you want the "values" here, the "keys" are the dates in your dictionary.

    with(
    local!json: "{
    ""09/03/2017"": {
    ""total"": 5
    },
    ""10/03/2017"": {
    ""total"": 5
    }
    }",
    local!dictionary: a!fromJson(local!json),
    local!objects: split(tostring(local!dictionary), ","),
    local!keysRaw: apply(
    mid(_, 1, 11),
    local!objects
    ),
    local!keysStripped: apply(stripwith(_, "[]:"), local!keysRaw),
    apply(index(local!dictionary, _, {}), local!keysStripped)
    )
Reply
  • 0
    Certified Lead Developer
    Here is an Appian implementation for your data model. Note that it could probably be cleaned up and it may not work for other data models! Also, you want the "values" here, the "keys" are the dates in your dictionary.

    with(
    local!json: "{
    ""09/03/2017"": {
    ""total"": 5
    },
    ""10/03/2017"": {
    ""total"": 5
    }
    }",
    local!dictionary: a!fromJson(local!json),
    local!objects: split(tostring(local!dictionary), ","),
    local!keysRaw: apply(
    mid(_, 1, 11),
    local!objects
    ),
    local!keysStripped: apply(stripwith(_, "[]:"), local!keysRaw),
    apply(index(local!dictionary, _, {}), local!keysStripped)
    )
Children
No Data