# man > cpanel_json_xs(1p)

---
type: CommandReference
command: cpanel_json_xs
mode: man
section: 1p
source: man-pages
---

## Quick Reference

- `cpanel_json_xs -t none <file` — JSON Lint: validate JSON file, exit with non-zero on error
- `cpanel_json_xs <src.json >pretty.json` — prettify JSON file
- `cpanel_json_xs -f storable-file <file` — convert Storable file to pretty-printed JSON
- `cpanel_json_xs -f storable-file -t yaml <file` — convert Storable file to YAML
- `cpanel_json_xs -f none -e '$_ = [1, 2, 3]'` — output Perl array as JSON
- `cpanel_json_xs -f bencode -e '$_ = join "\n", map @$_, @{$_->{"announce-list"}}' -t string` — extract tracker list from torrent file
- `lwp-request <url> | cpanel_json_xs` — fetch and pretty-print JSON from URL
- `cpanel_json_xs -f yaml-xs -t yaml-tiny <META.yml >MYMETA.yml` — convert between YAML formats

## Name

cpanel_json_xs - cPanel JSON::XS commandline utility

## Synopsis

shell
cpanel_json_xs [-v] [-f inputformat] [-t outputformat]
## Description

Converts between input and output formats (one of them is JSON). Default input is `json`, default output is `json-pretty`.

## Options

- `-v` — be slightly more verbose
- `-f fromformat` — read from STDIN in given format. One of:
  - `json` — JSON text (utf-8, utf16-be/le, utf32-be/le)
  - `json-nonref` — JSON per RFC 7159
  - `json-relaxed` — JSON with all relaxed options
  - `json-unknown` — JSON with `allow_unknown`
  - `storable` — Storable frozen value
  - `storable-file` — Storable file (two incompatible formats)
  - `bencode` — uses [Net::BitTorrent::Protocol::BEP03::Bencode](http://localhost/phpMan.php/perldoc/Net%3A%3ABitTorrent%3A%3AProtocol%3A%3ABEP03%3A%3ABencode/markdown), Bencode, or [Convert::Bencode](http://localhost/phpMan.php/perldoc/Convert%3A%3ABencode/markdown)
  - `clzf` — [Compress::LZF](http://localhost/phpMan.php/perldoc/Compress%3A%3ALZF/markdown) format
  - `eval` — evaluate code as Perl (non-utf-8), reverse of `-t dump`
  - `yaml` — loose YAML (requires YAML)
  - `yaml-tiny` — loose YAML (requires [YAML::Tiny](http://localhost/phpMan.php/perldoc/YAML%3A%3ATiny/markdown) or [CPAN::Meta::YAML](http://localhost/phpMan.php/perldoc/CPAN%3A%3AMeta%3A%3AYAML/markdown))
  - `yaml-xs` — strict YAML 1.2 (requires [YAML::XS](http://localhost/phpMan.php/perldoc/YAML%3A%3AXS/markdown))
  - `yaml-syck` — YAML (requires [YAML::Syck](http://localhost/phpMan.php/perldoc/YAML%3A%3ASyck/markdown))
  - `cbor` — CBOR (via [CBOR::XS](http://localhost/phpMan.php/perldoc/CBOR%3A%3AXS/markdown))
  - `string` — do not decode, treat as raw
  - `sereal` — Sereal (via [Sereal::Decoder](http://localhost/phpMan.php/perldoc/Sereal%3A%3ADecoder/markdown))
  - `none` — nothing read, creates `undef` (useful with `-e`)
- `-t toformat` — write to STDOUT in given format. One of:
  - `json`, `json-utf-8` — JSON, UTF-8 encoded
  - `json-pretty` — pretty-printed with sorted keys
  - `json-stringify` — as json-pretty with `allow_stringify`
  - `json-relaxed` — as json-pretty with `allow_stringify`, `allow_blessed`, `convert_blessed`, `allow_unknown`, `allow_tags`, `stringify` inf/nan
  - `json-utf-16le`, `json-utf-16be` — little/big endian UTF-16
  - `json-utf-32le`, `json-utf-32be` — little/big endian UTF-32
  - `storable` — Storable frozen value in network format
  - `storable-file` — Storable file in network format
  - `bencode` — see `-f` bencode
  - `clzf` — [Compress::LZF](http://localhost/phpMan.php/perldoc/Compress%3A%3ALZF/markdown) format
  - `yaml` — loose YAML (requires YAML)
  - `yaml-tiny` — loose YAML (requires [YAML::Tiny](http://localhost/phpMan.php/perldoc/YAML%3A%3ATiny/markdown) or [CPAN::Meta::YAML](http://localhost/phpMan.php/perldoc/CPAN%3A%3AMeta%3A%3AYAML/markdown))
  - `yaml-xs` — strict YAML 1.2 (requires [YAML::XS](http://localhost/phpMan.php/perldoc/YAML%3A%3AXS/markdown))
  - `yaml-syck` — YAML (requires [YAML::Syck](http://localhost/phpMan.php/perldoc/YAML%3A%3ASyck/markdown))
  - `dump` — [Data::Dump](http://localhost/phpMan.php/perldoc/Data%3A%3ADump/markdown)
  - `dumper` — [Data::Dumper](http://localhost/phpMan.php/perldoc/Data%3A%3ADumper/markdown) (note: does not handle self-referential structures correctly)
  - `string` — write data as raw string
  - `sereal` — Sereal (via [Sereal::Encoder](http://localhost/phpMan.php/perldoc/Sereal%3A%3AEncoder/markdown))
  - `none` — nothing written (useful with `-e`)
- `-e code` — evaluate Perl code after reading and before writing; data in `$_`, result written out

## Examples

shell
# JSON Lint: validate file
cpanel_json_xs -t none <isitreally.json
shell
# Prettify JSON
<src.json cpanel_json_xs >pretty.json
shell
# Convert Storable file to JSON
cpanel_json_xs -f storable-file <file
shell
# Convert Storable to YAML
cpanel_json_xs -f storable-file -t yaml <file
shell
# Output Perl array as JSON
cpanel_json_xs -f none -e '$_ = [1, 2, 3]'
shell
# Extract tracker list from torrent file
<torrentfile cpanel_json_xs -f bencode -e '$_ = join "\n", map @$_, @{$_->{"announce-list"}}' -t string
shell
# Fetch and pretty-print JSON from URL
lwp-request <http://cpantesters.perl.org/show/Cpanel-JSON-XS.json> | cpanel_json_xs
shell
# Convert between YAML formats
cpanel_json_xs -f yaml-xs -t yaml-tiny <META.yml >MYMETA.yml
cpanel_json_xs -f yaml-tiny -t yaml-xs <MYMETA.yml >XSMETA.yml
cpanel_json_xs -f yaml -t yaml <XSMETA.yml #BOOM!
## See Also

- [Cpanel::JSON::XS](http://localhost/phpMan.php/perldoc/Cpanel%3A%3AJSON%3A%3AXS/markdown)