Skip to content

Commit

Permalink
Improve performance of parsing newline delimited JSON in Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Mar 3, 2021
1 parent 07e2b6e commit ad44e31
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/jsonrepair.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,20 @@ export default function jsonrepair (text) {
// start of a new value after end of the root level object: looks like
// newline delimited JSON -> turn into a root level array

let stashedOutput = ''

while (tokenIsStartOfValue()) {
output = insertBeforeLastWhitespace(output, ',')

stashedOutput += output
output = ''

// parse next newline delimited item
parseObject()
}

// wrap the output in an array
return `[\n${output}\n]`
return `[\n${stashedOutput}${output}\n]`
}

throw new JsonRepairError('Unexpected characters', index - token.length)
Expand Down

0 comments on commit ad44e31

Please sign in to comment.