yarn audit --json returns invalid json

Created on 14 Nov 2018  Â·  1Comment  Â·  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
When I run yarn audit --json multiple root objects are being returned which makes parsing quite difficult as the JSON is invalid.

If the current behavior is a bug, please provide the steps to reproduce.
Running something like:

exec('yarn audit --json', (err, stdout, stderr) => {
  console.log(JSON.parse(stdout));
}

Will return:

SyntaxError: Unexpected token { in JSON at position 1480
    at JSON.parse (<anonymous>)
    at exec (/Users/user/web/project/index.js:62:16)
    at ChildProcess.exithandler (child_process.js:298:5)
    at ChildProcess.emit (events.js:182:13)
    at maybeClose (internal/child_process.js:961:16)
    at Socket.stream.socket.on (internal/child_process.js:380:11)
    at Socket.emit (events.js:182:13)
    at Pipe._handle.close (net.js:598:12)
✨  Done in 5.95s.

What is the expected behavior?
npm audit --json returns a valid json object for parsing. I would expect the same for yarn audit --json

Please mention your node.js, yarn and operating system version.
node: v10.6.0
yarn: 1.12.3
OS: MacOS Mojave 10.14.1

triaged

>All comments

The output is in json-lines format, and has been since the --json flag was first introduced in yarn. All the yarn commands output in this same format, not just audit.
There is some discussion in #5021

Was this page helpful?
0 / 5 - 0 ratings