https://github.com/chanwit/xq
Any Configuration Processor
https://github.com/chanwit/xq
Last synced: about 1 year ago
JSON representation
Any Configuration Processor
- Host: GitHub
- URL: https://github.com/chanwit/xq
- Owner: chanwit
- Created: 2020-03-04T14:22:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-07T13:15:30.000Z (over 6 years ago)
- Last Synced: 2025-06-12T01:04:01.841Z (about 1 year ago)
- Language: Groovy
- Homepage:
- Size: 62.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
xq - Any Configuration Processor
================================
`xq` aims to be a processor for any configuration format. Currently, `xq` supports JSON (`--json`), YAML (`--yaml`), and line-by-line text processing `--line`.
`xq` is generally slower than other processors, like `jq`, because it comes with a full programming language support. So `xq` can solve many limitations we might face when using other processors.
Examples
========
Here's the `data.json` used as our examples.
```
{
"apiVersion": "v1",
"kind": "Example",
"spec": {
"containers": [
{
"commands": [
"kube-proxy",
"--v=2"
]
}
]
}
}
```
### Get field `kind`
`$ cat data.json | xq --json '.kind' -o raw`
### Generate text wth template
`$ cat data.json | xq --json '.with{"apiVersion=${apiVersion}\nkind=${kind}\n"}' -o raw`
### Convert JSON to YAML
`$ cat data.json | xq --json '' -o yaml`
### Inplace edit and output as YAML
`$ cat data.json | xq --json '.tap{spec.containers[0].commands[1]="--v=4"}' -o yaml`
### Line replace with regexp
`$ cat data.json | xq --line '.replace(/kube-proxy/, "k8s-proxy")'`