1JSON_XS(1) User Contributed Perl Documentation JSON_XS(1)
2
3
4
6 json_xs - JSON::XS commandline utility
7
9 json_xs [-v] [-f inputformat] [-t outputformat]
10
12 json_xs converts between some input and output formats (one of them is
13 JSON).
14
15 The default input format is "json" and the default output format is
16 "json-pretty".
17
19 -v Be slightly more verbose.
20
21 -f fromformat
22 Read a file in the given format from STDIN.
23
24 "fromformat" can be one of:
25
26 json - a json text encoded, either utf-8, utf16-be/le, utf32-be/le
27 cbor - CBOR (RFC 7049, CBOR::XS), a kind of binary JSON
28 storable - a Storable frozen value
29 storable-file - a Storable file (Storable has two incompatible
30 formats)
31 bencode - use Convert::Bencode, if available (used by torrent
32 files, among others)
33 clzf - Compress::LZF format (requires that module to be installed)
34 eval - evaluate the given code as (non-utf-8) Perl, basically the
35 reverse of "-t dump"
36 yaml - YAML format (requires that module to be installed)
37 string - do not attempt to decode the file data
38 none - nothing is read, creates an "undef" scalar - mainly useful
39 with "-e"
40 -t toformat
41 Write the file in the given format to STDOUT.
42
43 "toformat" can be one of:
44
45 json, json-utf-8 - json, utf-8 encoded
46 json-pretty - as above, but pretty-printed
47 json-utf-16le, json-utf-16be - little endian/big endian utf-16
48 json-utf-32le, json-utf-32be - little endian/big endian utf-32
49 cbor - CBOR (RFC 7049, CBOR::XS), a kind of binary JSON
50 cbor-packed - CBOR using extensions to make it smaller
51 storable - a Storable frozen value in network format
52 storable-file - a Storable file in network format (Storable has two
53 incompatible formats)
54 bencode - use Convert::Bencode, if available (used by torrent
55 files, among others)
56 clzf - Compress::LZF format
57 yaml - YAML::XS format
58 dump - Data::Dump
59 dumper - Data::Dumper
60 string - writes the data out as if it were a string
61 none - nothing gets written, mainly useful together with "-e"
62 Note that Data::Dumper doesn't handle self-referential data
63 structures correctly - use "dump" instead.
64
65 -e code
66 Evaluate perl code after reading the data and before writing it out
67 again - can be used to filter, create or extract data. The data
68 that has been written is in $_, and whatever is in there is written
69 out afterwards.
70
72 json_xs -t none <isitreally.json
73
74 "JSON Lint" - tries to parse the file isitreally.json as JSON - if it
75 is valid JSON, the command outputs nothing, otherwise it will print an
76 error message and exit with non-zero exit status.
77
78 <src.json json_xs >pretty.json
79
80 Prettify the JSON file src.json to dst.json.
81
82 json_xs -f storable-file <file
83
84 Read the serialised Storable file file and print a human-readable JSON
85 version of it to STDOUT.
86
87 json_xs -f storable-file -t yaml <file
88
89 Same as above, but write YAML instead (not using JSON at all :)
90
91 json_xs -f none -e '$_ = [1, 2, 3]'
92
93 Dump the perl array as UTF-8 encoded JSON text.
94
95 <torrentfile json_xs -f bencode -e '$_ = join "\n", map @$_, @{$_->{"announce-list"}}' -t string
96
97 Print the tracker list inside a torrent file.
98
99 lwp-request http://cpantesters.perl.org/show/JSON-XS.json | json_xs
100
101 Fetch the cpan-testers result summary "JSON::XS" and pretty-print it.
102
104 Copyright (C) 2008 Marc Lehmann <json@schmorp.de>
105
106
107
108perl v5.38.0 2023-07-20 JSON_XS(1)