Merge Dictionaries

I have multiple dictionaries, each with a unique key, value pair. I would like to merge these dictionaries into a single dictionary. Any suggestions on how to accomplish this would be appreciated.

Parents
  • I've accomplished this effectively using these three expression rules:

    extractKeysFromDictionary:

    a!forEach(
      items: xpathsnippet(toxml(ri!dictionary), "/*/*"),
      expression: index(split(index(split(fv!item, " "), 1), "<"), 2)
    )


    extractValuesFromDictionary:
    a!forEach(
      items: rule!extractKeysFromDictionary(ri!dictionary),
      expression: property(ri!dictionary, fv!item)
    )


    combineDictionaries:
    reduce(
      fn!insert,
      ri!dictionary1,
      merge(
        rule!extractValuesFromDictionary(ri!dictionary2),
        rule!extractKeysFromDictionary(ri!dictionary2)
      )
    )

Reply
  • I've accomplished this effectively using these three expression rules:

    extractKeysFromDictionary:

    a!forEach(
      items: xpathsnippet(toxml(ri!dictionary), "/*/*"),
      expression: index(split(index(split(fv!item, " "), 1), "<"), 2)
    )


    extractValuesFromDictionary:
    a!forEach(
      items: rule!extractKeysFromDictionary(ri!dictionary),
      expression: property(ri!dictionary, fv!item)
    )


    combineDictionaries:
    reduce(
      fn!insert,
      ri!dictionary1,
      merge(
        rule!extractValuesFromDictionary(ri!dictionary2),
        rule!extractKeysFromDictionary(ri!dictionary2)
      )
    )

Children
No Data

 Discussion posts and replies are publicly visible