Assuming that your file is actual json and that's the input of the function (i.e., you're not parsing it before) and that json objects will always be separated by a new line, something like this should do the trick:
const addCommas = jsonStr => jsonStr.replace('}\n{', '},{') const jsonArray = jsonStr => `[${addCommas(jsonStr)}]`
If you want it to return an actual array, rather than a json array, you can simply do:
const addCommas = jsonStr => jsonStr.replace('}\n{', '},{') const jsonArray = jsonStr => JSON.parse(`[${addCommas(jsonStr)}]`)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Assuming that your file is actual json and that's the input of the function (i.e., you're not parsing it before) and that json objects will always be separated by a new line, something like this should do the trick:
If you want it to return an actual array, rather than a json array, you can simply do: