This commit is contained in:
Mike Farah
2023-11-23 11:59:14 +11:00
parent b06ab987b1
commit cac23ac003
11 changed files with 170 additions and 14 deletions
+6 -6
View File
@@ -14,7 +14,7 @@ Given a sample.json file of:
```
then
```bash
yq -P '.' sample.json
yq -p=json sample.json
```
will output
```yaml
@@ -30,16 +30,16 @@ Given a sample.json file of:
```
then
```bash
yq -P '.' sample.json
yq -p=json sample.json
```
will output
```yaml
a: Easy! as one two three
b:
c: 2
d:
- 3
- 4
c: 2
d:
- 3
- 4
```
## Encode json: simple
+33 -1
View File
@@ -1,5 +1,33 @@
## Basic example
## Basic input example
Given a sample.lua file of:
```lua
return {
["country"] = "Australia"; -- this place
["cities"] = {
"Sydney",
"Melbourne",
"Brisbane",
"Perth",
};
};
```
then
```bash
yq -oy '.' sample.lua
```
will output
```yaml
country: Australia
cities:
- Sydney
- Melbourne
- Brisbane
- Perth
```
## Basic output example
Given a sample.yml file of:
```yaml
---
@@ -101,6 +129,8 @@ numbers:
- octal: 0o30
- float: 123.45
- infinity: .inf
plus_infinity: +.inf
minus_infinity: -.inf
- not: .nan
```
@@ -134,6 +164,8 @@ return {
},
{
["infinity"] = (1/0);
["plus_infinity"] = (1/0);
["minus_infinity"] = (-1/0);
},
{
["not"] = (0/0);
+1 -3
View File
@@ -129,15 +129,13 @@ zoo:
```
## Parse xml: force all as an array
Because of the way yq works, when updating everything you need to update the children before the parents. By default `..` will match parents first, so we reverse that before updating.
Given a sample.xml file of:
```xml
<zoo><thing><frog>boing</frog></thing></zoo>
```
then
```bash
yq -oy '([..] | reverse | .[]) |= [] + .' sample.xml
yq -oy '.. |= [] + .' sample.xml
```
will output
```yaml