Skip to content

Commit

Permalink
Merge pull request #39 from Inist-CNRS/avoid-bad-json
Browse files Browse the repository at this point in the history
to avoid wrong JSON syntax, if there no keys to extract
  • Loading branch information
touv authored Feb 25, 2020
2 parents e58a237 + eea93aa commit c8bfb85
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/lodex/src/formatOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ function formatOutput(data, feed) {
const values = keys.map((p) => get(data, p));
feed.write('{');
if (keys.length > 0) {
let check = false;
keys.forEach((k, index) => {
if (values[index]) {
check = true;
feed.write(index === 0 ? ' ' : ',');
feed.write(json(k));
feed.write(':');
feed.write(json(values[index]));
}
});
feed.write(',');
if (check) {
feed.write(',');
}
}
feed.write(`"${keyName}":[`);
} else {
Expand Down

0 comments on commit c8bfb85

Please sign in to comment.