wwkimball/yamlpath

Support for array notation [] in paths

ponson-thankavel opened this issue · 1 comments

Is your feature request related to a problem? Please describe.

It will be great if the tool can support array notation [] like below

department.employees[0].name
department.employees[0].age
department.employees[1].name
department.employees[1].age

Describe the solution you'd like

Here are 2 different yaml files

yaml-1

a:
  - hello
  - world

yaml-2

a:
  0: hello
  1: world

I run below command on both of the above yamls

yaml-paths --nofile --expand --keynames --noescape --values --search='=~/.*/' yaml-1.yaml
yaml-paths --nofile --expand --keynames --noescape --values --search='=~/.*/' yaml-2.yaml

I get same output for both yaml files

a.0: hello
a.1: world

I think the correct output for yaml-1 is:-

a[0]: hello
a[1]: world

Describe alternatives you've considered

couldn't find any alternate solution

Additional context

none

The tool does support Array Notation. The issue you have presented is simply that your sample data does not contain any Arrays. In YAML, an Array is written as:

thisIsAnArray:
  - element 0
  - element 1
  - element 2
  - and so on

What you have presented in this issue are various Hashes. This is as much a Hash:

thisIsNOTanArray:
  0: This is just a Hash child whose key name happens to be '0'
  1: Using digits for Hash keys does not create an Array; it's still just a Hash

As this:

thisIsAlsoNOTanArray:
  one: Anything with a key and a : forms a map
  two: Just because your key name may have -- or be only -- digits does not change a Hash into an Array