-
-
Notifications
You must be signed in to change notification settings - Fork 23
Segment: Hash Keys
When your YAML data contains a Hash data structure, use the Hash Keys as named identifiers to select them. For example:
some_hash_name:
child: value
child2: value2
childN: valueN
To select value2
from this data, use this YAML Path: some_hash_name.child2
or /some_hash_name/child2
.
No matter how deeply nested your Hash data is, YAML Path can find the data you need. For example:
a_hash:
with:
any:
depth:
of:
child:
nodes: some_value
To select some_value
from this YAML data, use this YAML Path: a_hash.with.any.depth.of.child.nodes
or /a_hash/with/any/depth/of/child/nodes
Users may sometimes encounter YAML with weird characters within key names. For example, a user may prefer to use dot-notation for YAML Paths but suddenly encounter Hash keys with dots in their names. YAML Path solves this situation by permitting String demarcation symbols in key names.
some_hash:
a.child.with.dotted.key.1: value1
a.child.with.dotted.key.2: value2
a.child.with.dotted.key.N: valueN
When you want to access value2
, YAML Path permits these forms (note that forward-slash notation obviates the need for String demarcation on these particular dotted keys):
- some_hash."a.child.with.dotted.key.2"
- some_hash.'a.child.with.dotted.key.2'
- /some_hash/a.child.with.dotted.key.2
For the same key, if you forget to demarcate it properly, YAML Path will expect the YAML data to be structured like this:
some_hash:
a:
child:
with:
dotted:
key:
-
-
- value2
YAML Path recognizes the \
symbol to ignore (escape) all special symbols -- including the \
symbol, itself -- in Hash Key names so as to avoid triggering unwanted segment identification. This can be used to avoid employing String demarcation symbols, though it may be more symbol utilization for key names with more than one special symbol. Rewriting the Demarcation For Key Names examples with the escape symbol would yield these YAML Paths:
- some_hash.a.child.with.dotted.key.2
- some_hash.a.child.with.dotted.key.2
- /some_hash/a.child.with.dotted.key.2
Note the third example was unaffected because the .
is not mistaken for a YAML Path segment separator when using forward-slash notation. However, if the YAML data were to have a key named something like key_with/forward/slashes/in_its_name
, and you wanted to use forward-slash notation anyway, you'd have to escape those forward-slashes like this: key_with\/forward\/slashes\/in_its_name
.