Skip to content

Iterate over data container, convert to slist #5276

Answered by nickanderson
olehermanse asked this question in Q&A
Discussion options

You must be logged in to vote

I was able to accomplish this without using classic associative arrays using maparray().

https://docs.cfengine.com/docs/3.21/reference-functions-maparray.html

bundle agent __main__
{
  vars:
    "data_container"
      data => '[{"name": "a", "value": "b"},{"name": "c", "value": "d"}]';

    # "data_container_index"
    #   slist => getindices("data_container");
    # "data_container_array[$(data_container_index)]"
    #   string => "$(data_container[$(data_container_index)][name])";

    # Use mapdata() to build a new data container where the keys are the pacakge name
    # We reference back to 'd' because this.k is the positional location in the array returned by packagesmatching()
    "…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@olehermanse
Comment options

Answer selected by olehermanse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants