Skip to content

Commit c8efc37

Browse files
committed
Major change to --json output
1 parent ff75805 commit c8efc37

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

README.md

+30-12
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,44 @@ If you prefer CSV because it loads more smoothly into MS Excel, use the `--csv`
188188
```
189189
% mlst --csv Peptobismol.fna.gz > mlst.csv
190190
```
191-
JSON output is available too:
191+
JSON output is available too; it returns an array of dictionaries, one per
192+
input file. The `id` will be the same as `filename` unless `--label` is
193+
used, but that only works when scanning a single file.
192194
```
193-
% mlst -q --json out.json --label Sepi test/example.fna.gz
195+
% mlst -q --json out.json test/example.gbk.gz test/novel.fasta.bz2
194196
% cat out.json
195-
{
196-
"Sepi" : {
197-
"sequence_type" : "184",
197+
[
198+
{
199+
"scheme" : "sepidermidis",
198200
"alleles" : {
199-
"arcC" : "16",
201+
"mutS" : "1",
200202
"yqiL" : "1",
201-
"gtr" : "2",
202-
"pyrR" : "2",
203203
"tpiA" : "1",
204+
"pyrR" : "2",
205+
"gtr" : "2",
204206
"aroE" : "1",
205-
"mutS" : "1"
207+
"arcC" : "16"
208+
},
209+
"sequence_type" : "184",
210+
"filename" : "test/example.gbk.gz",
211+
"id" : "test/example.gbk.gz"
212+
},
213+
{
214+
"sequence_type" : "-",
215+
"filename" : "test/novel.fasta.bz2",
216+
"scheme" : "spneumoniae",
217+
"alleles" : {
218+
"gki" : "2",
219+
"aroE" : "7",
220+
"ddl" : "22",
221+
"gdh" : "15",
222+
"xpt" : "1",
223+
"recP" : "~10",
224+
"spi" : "6"
206225
},
207-
"filename" : "test/example.fna.gz",
208-
"scheme" : "sepidermidis"
226+
"id" : "test/novel.fasta.bz2"
209227
}
210-
}
228+
]
211229
```
212230
You can also save the "novel" alleles for submission to PubMLST::
213231
```

bin/mlst

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use Digest::MD5 qw(md5_hex);
1818
#..............................................................................
1919
# Globals
2020

21-
my $VERSION = "2.18.1";
21+
my $VERSION = "2.19.0";
2222
my $EXE = basename( $FindBin::RealScript );
2323
my $AUTHOR = 'Torsten Seemann';
2424
my $URL = 'https://github.com/tseemann/mlst';
@@ -98,7 +98,7 @@ msg("Excluding $num_excluded schemes:", (keys %exclude)) if $num_excluded > 0;
9898
#..............................................................................
9999
# Output results
100100

101-
my %json;
101+
my $json;
102102

103103
# output the header for the old style syntax
104104
if ($scheme and $legacy) {
@@ -149,7 +149,8 @@ for my $argv (@ARGV)
149149
}
150150

151151
if ($json_fn) {
152-
$json{$LABEL} = {
152+
push @$json, {
153+
'id' => $LABEL,
153154
'filename' => $argv,
154155
'scheme' => $sch,
155156
'sequence_type' => $ST,
@@ -166,7 +167,7 @@ for my $argv (@ARGV)
166167
if ($json_fn) {
167168
msg("Writing JSON: $json_fn");
168169
path($json_fn)->spew(
169-
to_json( \%json, {ascii=>1,pretty=>1} ),
170+
to_json( $json, {ascii=>1,pretty=>1} ),
170171
);
171172
}
172173

0 commit comments

Comments
 (0)