Skip to main content

Command-line TOML/JSON/INI/YAML/XML processor using jq c bindings

Project description

wildq - Command-line TOML/JSON/INI/YAML/XML/HCL processor using jq c bindings

GitHub image Build Status

Purpose of this package is to provide a simple wrapper arround jq for different formats. I'm tired of searching a package doing yaml jq, toml jq, ini jq etc. mainly used for scripting.

This script uses:

Installation

pip install wildq

Usage

wildq [--yaml|--json|--toml|--ini|--xml|--hcl> <jq filter> [file]

There is also a shorter command wq comming with the package.

Output is similar to jq -MCr (no color, no compact and no quote on single value)

Like jq cli, wildq supports both of stdin and file to the function

See examples to get some example.

Content of examples/json.json

{
    "general": {
        "user": "admin"
    },
    "keys": [
        {"key": "value1"},
        {"key": "value2"},
        "alone"
    ]
}
cat examples/json.json | wildq --json ".keys[]"
{
    "key": "value1"
}
{
    "key": "value2"
}
alone

or

wildq --json ".keys[]" examples/json.json
{
    "key": "value1"
}
{
    "key": "value2"
}
alone

or

wq --json ".keys[]" examples/json.json
{
    "key": "value1"
}
{
    "key": "value2"
}
alone

For TOML

cat examples/toml.toml | wildq --toml ".keys[]"
{
    "key": "value1"
}
{
    "key": "value2"
}
alone

For INI (no array)

cat examples/ini.ini | wildq --ini ".keys"
{
    "key1": "value1",
    "key2": "value2"
}

For XML

cat examples/xml.xml | wildq --xml "."
{
    "root": {
        "general": {
            "user": "admin"
        },
        "keys": {
            "element": [
                {
                    "key": "value1"
                },
                {
                    "key": "value2"
                },
                "alone"
            ]
        }
    }
}

For YAML

cat examples/yaml.yaml  | wildq --yaml ".keys[]"
{
    "key1": "value1"
}
{
    "key2": "value2"
}
alone

For HCL

cat examples/hcl.hcl  | wildq --hcl ".keys[]"
{
    "key": "value1"
}
{
    "key": "value2"
}

Tips and tricks

Loop on keys in bash without creating a subshell

wildq --toml "keys[]" examples/toml.toml | while read -r key 
do
    echo "Getting key ${key}"
done

TODO

  • support all jq types
  • add tests...
  • add more control over filters and files
  • detect automagically filetype
  • use click for the CLI

Contributing

Merge requests are welcome :)

License

Licensed under the terms of the Apache License, Version 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

wildq-1.0.6-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file wildq-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: wildq-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for wildq-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1b3aad7e5cb1b72b476cb70c0e512dbb78d22d111628ba9598a5ee5d355a65e1
MD5 a66842830c3b035ec4a5d15c4115c9da
BLAKE2b-256 54ce7508d3dc4affe8f7b1fc31ceb22d31cc65ef101c940c9c307050f135fad1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page