How to handle "[key1:value1,key2:value2]"

I have got a input string like "[key1:value1,key2:value2]", how to get the value by key?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hi  

    I have developed a solution that achieve this dynamically. Below is the code for your reference.

    a!localVariables(
    local!input: "[key1:value1,key2:value2,key3:value3,key4:value4]",
    local!stripText: mid(local!input, 2, len(local!input) - 2),
    local!tempString: split(split(local!stripText, ","), ":"),
    local!dict: a!map(),
    local!updatedMaps: a!forEach(
    items: local!tempString,
    expression: if(
    mod(fv!index, 2) = 0,
    {},
    a!update(
    local!dict,
    fv!item,
    index(local!tempString, fv!index + 1, null())
    )
    )
    ),
    local!keys: a!flatten(
    a!forEach(
    items: local!updatedMaps,
    expression: a!keys(fv!item)
    )
    ),
    a!update(
    a!map(),
    local!keys,
    a!forEach(
    items: local!updatedMaps,
    expression: index(fv!item, a!keys(fv!item), null)
    )
    )
    )

Reply
  • 0
    Certified Senior Developer

    Hi  

    I have developed a solution that achieve this dynamically. Below is the code for your reference.

    a!localVariables(
    local!input: "[key1:value1,key2:value2,key3:value3,key4:value4]",
    local!stripText: mid(local!input, 2, len(local!input) - 2),
    local!tempString: split(split(local!stripText, ","), ":"),
    local!dict: a!map(),
    local!updatedMaps: a!forEach(
    items: local!tempString,
    expression: if(
    mod(fv!index, 2) = 0,
    {},
    a!update(
    local!dict,
    fv!item,
    index(local!tempString, fv!index + 1, null())
    )
    )
    ),
    local!keys: a!flatten(
    a!forEach(
    items: local!updatedMaps,
    expression: a!keys(fv!item)
    )
    ),
    a!update(
    a!map(),
    local!keys,
    a!forEach(
    items: local!updatedMaps,
    expression: index(fv!item, a!keys(fv!item), null)
    )
    )
    )

Children