mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-05 00:54:51 +08:00
v4.40.3
This commit is contained in:
+6
-6
@@ -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
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user