Skip to content

Commit

Permalink
Add docs example of field reorder via record expressions (#4902)
Browse files Browse the repository at this point in the history
  • Loading branch information
philrz authored Nov 30, 2023
1 parent beb2760 commit 40739bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/language/functions/order.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ the empty record type, i.e.,
order(val, <{}>)
```

:::tip Note
[Record expressions](../expressions.md#record-expressions) can also be used to
reorder fields without specifying types ([example](../shaping.md#order)).
:::

### Examples

_Order a record_
Expand Down
25 changes: 25 additions & 0 deletions docs/language/shaping.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,31 @@ about the `uid` field as it is not in the `connection` type:
}
```

As an alternative to the `order` function,
[record expressions](expressions.md#record-expressions) can be used to reorder
fields without specifying types. For example:

```mdtest-command
zq -Z 'yield {kind,client,server,...this}' sample.json
```

also produces

```mdtest-output
{
kind: "dns",
client: {
addr: "10.47.1.100",
port: 41772
},
server: {
addr: "10.0.0.100",
port: 53
},
uid: "C2zK5f13SbCtKcyiW5"
}
```

### Shape

The `shape` function brings everything together by applying `cast`,
Expand Down

0 comments on commit 40739bd

Please sign in to comment.