Extend an array in YAML?

Since the already commented issue#35 exists, merge-keys << doesn’t help you. It only merges/inserts referenced keys into a map (see YAML docs merge). Instead you should work with sequences and use anchor & and alias *.

So your example should look like this:

base_list: &base
    - 1
    - 2

extended: &ext
    - 3

extended_list:
    [*base, *ext]

Will give result in output like this (JSON):

{
  "base_list": [
    1, 
    2
  ], 
  "extended": [
    3
  ], 
  "extended_list": [
    [
      1, 
      2
    ], 
    [
      3
    ]
  ]
} 

Although not exactly what you expected, but maybe your parsing/loading environment can flatten the nested array/list to a simple array/list.

You can always test YAML online, for example use:

  • http://ben-kiki.org/ypaste
  • Online YAML Parser

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)