Skip to content

m json

Format a json payload.

similar to python -m json.tool but instead it uses 2 spaces for indentation::

$ echo '{"a":99}' | m json
{
  "a": 99
}

It is worth noting that if you have access to jq or yq then it should be used instead of m json::

$ echo '{"a":99}' | jq
{
  "a": 99
}
  • jq: https://stedolan.github.io/jq/manual/
  • yq: https://mikefarah.gitbook.io/yq/
Source code in m/cli/commands/json.py
class Arguments(BaseModel):
    """Format a json payload.

    similar to `python -m json.tool` but instead it uses 2 spaces
    for indentation::

        $ echo '{"a":99}' | m json
        {
          "a": 99
        }

    It is worth noting that if you have access to `jq` or `yq` then
    it should be used instead of `m json`::

        $ echo '{"a":99}' | jq
        {
          "a": 99
        }

    - jq: https://stedolan.github.io/jq/manual/
    - yq: https://mikefarah.gitbook.io/yq/
    """

    payload: Any = Arg(
        default='@-',
        help='json data: @- (stdin), @filename (file), string',
        positional=True,
        validator=validate_json_payload,
    )

    sort_keys: bool = Arg(
        default=False,
        help='sort the output of dictionaries alphabetically by key',
    )

Options

--sort-keys

  • default: false

sort the output of dictionaries alphabetically by key

Positional arguments

payload

  • default: '@-'

json data: @- (stdin), @filename (file), string