如何将JSON转换为JSON行

如何将JSON转换为JSON行,json,jsonlines,Json,Jsonlines,我是JavaScript新手。我正在构建一个对象数组。我需要把它串起来,去掉方括号,在“,”上拆分每个对象,然后放在新行上 需要从以下方面着手: [{"product_id":297316,"id":1,"rating":3},{"product_id":98133,"id":2,"rating":2}] 为此: "{"product_id":2

我是JavaScript新手。我正在构建一个对象数组。我需要把它串起来,去掉方括号,在“,”上拆分每个对象,然后放在新行上

需要从以下方面着手:

[{"product_id":297316,"id":1,"rating":3},{"product_id":98133,"id":2,"rating":2}]
为此:

"{"product_id":297316,"id":1,"rating":3}",
"{"product_id":98133,"id":2,"rating":2}"

如果你说的换行是指打印,你可以:

for (let product of products) {
  console.log(JSON.stringify(product))
}
products.map(JSON.stringify).join('\n')
或者,如果要生成换行分隔字符串,可以执行以下操作:

for (let product of products) {
  console.log(JSON.stringify(product))
}
products.map(JSON.stringify).join('\n')

所以。。。。我知道你们需要了解测试的代码行,或者什么信息来自API或者类似的东西

大多数情况下,我在Sublime Text 3中快速使用replace和regex,如:


如果您使用Google Chrome,可以使用名为JSONView的插件自动解析json信息。如果你想进入职业大联盟,你可以用邮递员。