Hello Everyone, Does anyone know of a way to get the a!fromJson function t

Certified Associate Developer
Hello Everyone,
Does anyone know of a way to get the a!fromJson function to respect arrays? Ie:

a!fromJson({"Values":["Alph;a","Beta","Delta"]})

will return a dictionary. When I index 'values' from the dictionary I get a single string representation of the array I started with instead of the array itself.

The problem appears to be that dictionaries themselves don't support arrays as values - for example this expression returns 1 instead of 3:
load(
local!dict: {Values: {1, 2, 3}},
length(local!dict.Values)
)

Does anyone have a way around this shortcoming?

OriginalPostID-197406

OriginalPostID-197406

  Discussion posts and replies are publicly visible

Parents
  • @jpheh One way I would generally prefer to do it is casting. Let's take the example which is quoted by you and this is how we can work around it:

    load(
    local!dict: {Values: {1, 2, 3}},
    length(cast(101,local!dict.Values))
    )

    To the best of my knowledge, the structure {Values: {1, 2, 3}} is a custom structure created on-the-fly, and it is similar to label-value pairs. When it comes to CDT, we designate a field in CDT to hold particular type of data (such as Integer, Text, Text Multiple etc) at time of its creation. But in case of these Label Value pairs, they are just dictionaries that will store data in 'Any Type' format as we don't designate the data type of them. So we should cast the data to a desired data type prior to using the values in them.
Reply
  • @jpheh One way I would generally prefer to do it is casting. Let's take the example which is quoted by you and this is how we can work around it:

    load(
    local!dict: {Values: {1, 2, 3}},
    length(cast(101,local!dict.Values))
    )

    To the best of my knowledge, the structure {Values: {1, 2, 3}} is a custom structure created on-the-fly, and it is similar to label-value pairs. When it comes to CDT, we designate a field in CDT to hold particular type of data (such as Integer, Text, Text Multiple etc) at time of its creation. But in case of these Label Value pairs, they are just dictionaries that will store data in 'Any Type' format as we don't designate the data type of them. So we should cast the data to a desired data type prior to using the values in them.
Children
No Data