Skip to content
Advertisement

How do I replace a json comma with a new line

im trying to replace every comma in my json file:

{
  "friends": {
    "count": "9",
    "friends": [
      "Xdevil_blueX",
      "SpectakularBaby_YT",
      "kingdondon96",
      "Xxaland366xX",
      "imbadinarsenal_99",
      "EnderMox2",
      "No0dles_s",
      "cracon999",
      "ionwarrior123"
    ]
  }
}

so i need to replace every comma in the friends list with a new line

for example i want the output to be like this (just note im not using node.js)

Xdevil_blueX
SpectakularBaby_YT
kingdondon96
Xxaland366xX
imbadinarsenal_99
EnderMox2
No0dles_s
cracon999
ionwarrior123

Advertisement

Answer

You can easily do that taking the array ‘friends’ and turning it into a string while you break the line in each comma. follows like this:

friends.join('n')
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement