# JSON ## Visão geral O módulo `json` fornece utilitários locais para formatação, validação, edição, comparação e conversão de JSON. ## Comandos da CLI ```bash brutils json format --file ./config.json --sort-keys brutils json minify --value '{"name":"brutils","ok":true}' brutils json validate --value '{"ok":true}' brutils json get --file ./config.json --path server.port brutils json set --file ./config.json --path flags.dev --set-value true --in-place brutils json delete --file ./config.json --path obsoleteFlag --in-place brutils json diff --left ./left.json --right ./right.json brutils json merge --file ./base.json ./override.json brutils json to-yaml --value '{"name":"brutils","ok":true}' ``` ## Ações | Ação | Uso | Descrição | | ---------- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------ | | `format` | `brutils json format (--file \| --value ) [--indent ] [--sort-keys] [--in-place]` | Formata JSON para facilitar a leitura. | | `minify` | `brutils json minify (--file \| --value ) [--in-place]` | Minifica JSON. | | `validate` | `brutils json validate (--file \| --value )` | Valida a sintaxe JSON. | | `get` | `brutils json get (--file \| --value ) --path ` | Lê um caminho no JSON. | | `set` | `brutils json set (--file \| --value ) --path --set-value [--in-place]` | Grava um valor em um caminho no JSON. | | `delete` | `brutils json delete (--file \| --value ) --path [--in-place]` | Remove um caminho do JSON. | | `diff` | `brutils json diff --left --right ` | Compara dois arquivos JSON ou valores JSON informados diretamente. | | `merge` | `brutils json merge [--file ...] [--value ...]` | Mescla várias fontes JSON. | | `to-yaml` | `brutils json to-yaml (--file \| --value )` | Converte JSON para YAML. | ## Opções | Opção | Aplicável a | Tipo | Descrição | | ------------------------ | ----------------------------------- | -------- | -------------------------------------------------------------- | | `--file ` | maioria das ações | string | Lê JSON de um arquivo. | | `--value ` | maioria das ações | string | Lê JSON informado diretamente. | | `--path ` | `get`, `set`, `delete` | string | Caminho JSON no qual realizar a operação. | | `--set-value ` | `set` | string | Novo valor JSON para o caminho. | | `--indent ` | `format` | inteiro | Tamanho da indentação para facilitar a leitura. | | `--sort-keys` | `format` | booleano | Ordena recursivamente as chaves dos objetos antes da exibição. | | `--left ` | `diff` | string | Caminho do arquivo JSON ou valor JSON da esquerda. | | `--right ` | `diff` | string | Caminho do arquivo JSON ou valor JSON da direita. | | `--in-place` | `set`, `delete`, `format`, `minify` | booleano | Grava as alterações de volta no arquivo de entrada. | ## Observações - `--in-place` exige `--file`, pois um JSON informado diretamente não pode ser sobrescrito. - `merge` aceita vários caminhos `--file` e/ou várias strings JSON `--value` no mesmo comando. - `brutils json --help` exibe exemplos e instruções de uso de todo o módulo.