Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Clone this wiki locally
Almost any transformation on a Catmandu item contains a path to the part of the item that needs to be changed. To upcase the title field in an item the Fix upcase need to be used:
A field can be nested in key-value-pairs (objects). To access the field deep in a key-value-pair, the dot-notation should be used:
If a part of an item contains a list of fields than the index-notation should be used. Use index 0 to point to the first item in a list, index 1 to point to the second item in a list, index 3 to the third, etc, etc.
upcase(my.data.2.title) # upcase the title of the 3rd item in the my.data list
For example, given this YAML input:
___ title: My Little Pony my: colors: - red - green - blue nested: a: b: c: Hoi!
The value 'My Little Pony' can be accessed using the path:
The value 'green' can be accessed using the path:
The value 'Hoi!' can be accessed using the path:
Wildcards are used to point to relative positions or many positions in a list.
To point to the first item in a list (e.g. the value 'red' in the example above) the wildcard $first can be used:
To point to the last item in a list (e.g. the value 'blue' in the example above) the wildcard $last can be used:
In some cases, one needs to point to a position before the first item in a list. For instance, add a new field before the color 'red' in our example above, the wildcard '$prepend' should be used:
This wildcard can be used in the functions like set_field:
To add a new field add the end of a list (after the color 'blue'), the wildcard '$append' should be used:
The star notation is used to point to all the items in a list:
To upcase all the colors use:
When lists are nested inside lists, then wildcards can also be nested:
The above trick can be used when the my field contains a list which contains a color field which contains again a list of data. E.g.
--- my: - colors: - red - blue - colors: - yellow - green
MARC, MAB, PICA paths
For some data formats is can be quite difficult to extract data by the exact position of a field. In data formats such as MARC, one is unsually not interested in a field in the 17th position which contains a subfield in position 3. MARC contains tags and subfields, which can be at any position in the MARC record.
Specialized Fix functions for MARC, MAB and PICA make it easier to access data by changing the Path syntax. For instance, to copy the 245a field in a MARC record to the title field one can write:
In the context of a marc_map Fix the "245a" Path is a MARC Path that points to a part of the MARC record. These MARC Paths only work in MARC Fixes (marc_map, marc_add, marc_set, marc_remove). It is not possible to use these paths in other Catmandu fix functions:
marc_map("245a",title) # This will work copy_field("246a","other_title") # This will NOT work
Consult the documentation of the different specialised packages for the Path syntax that can be used.