Skip to content

Instantly share code, notes, and snippets.

@nickanderson
Created November 7, 2022 15:00
Show Gist options
  • Save nickanderson/58b08dba1433c5b4291559a803985009 to your computer and use it in GitHub Desktop.
Save nickanderson/58b08dba1433c5b4291559a803985009 to your computer and use it in GitHub Desktop.
Work with yaml and output in specific format

Use the YAML to generate output matching the following format:

scifi::isbn: 'isbn' with book_name: 'book_name'
travel::isbn: 'isbn' with book_name: 'book_name'

Policy:

bundle agent main
{
  vars:
    "yaml" data => parseyaml ('
      books:
        scifi_schema:
          isbn: "isbn_scifi"
          book_name: "book_name_scifi"
        travel_schema:
          isbn: "isbn_travel"
          book_name: "book_name_travel"
    ');
    "schemas" slist => getindices( "@(yaml[books])" );
  reports:

    "$(with)::isbn: '$(yaml[books][$(schemas)][isbn])' with book_name: '$(yaml[books][$(schemas)][book_name])'"
      with => regex_replace( "$(schemas)", "_schema", "", "g" );
}

Output:

R: scifi::isbn: 'isbn_scifi' with book_name: 'book_name_scifi'
R: travel::isbn: 'isbn_travel' with book_name: 'book_name_travel'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment