From 450a4b4d379b1062696a4a372e720cbad3c1015c Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sun, 12 May 2024 12:14:14 +1000 Subject: [PATCH] Added property number example --- operators/slice-array.md | 2 +- usage/properties.md | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/operators/slice-array.md b/operators/slice-array.md index 40ebea49..9b89210b 100644 --- a/operators/slice-array.md +++ b/operators/slice-array.md @@ -2,7 +2,7 @@ The slice array operator takes an array as input and returns a subarray. Like the `jq` equivalent, `.[10:15]` will return an array of length 5, starting from index 10 inclusive, up to index 15 exclusive. Negative numbers count backwards from the end of the array. -You may leave out the first or second number, which will will refer to the start or end of the array respectively. +You may leave out the first or second number, which will refer to the start or end of the array respectively. ## Slicing arrays Given a sample.yml file of: diff --git a/usage/properties.md b/usage/properties.md index 6eed4ef0..50217032 100644 --- a/usage/properties.md +++ b/usage/properties.md @@ -230,6 +230,23 @@ person: - pizza ``` +## Decode properties: numbers +All values are assumed to be strings when parsing properties, but you can use the `from_yaml` operator on all the strings values to autoparse into the correct type. + +Given a sample.properties file of: +```properties +a.b = 10 +``` +then +```bash +yq -p=props ' (.. | select(tag == "!!str")) |= from_yaml' sample.properties +``` +will output +```yaml +a: + b: 10 +``` + ## Decode properties - array should be a map If you have a numeric map key in your property files, use array_to_map to convert them to maps.