11

I have a JSON object that I am defining like this:

    "COVER": {
        "H1": "XXX",
        "P1": "Very long text" +
              "More very long text"
    }

I tried to split the text onto two lines but I get a Visual Studio error messages saying "missing a comma after an object member"

  • and you want to do this without inserting line break inside the json string? – Parv Sharma May 14 '15 at 07:04
  • 2
    Yes I don't want a line break. It's just my string is very long and it is hard to see it without using a scroll in the editory. –  May 14 '15 at 07:06
  • http://stackoverflow.com/questions/2392766/multiline-strings-in-json – nitin May 14 '15 at 07:08
  • Possible duplicate of [Multiline strings in JSON](https://stackoverflow.com/questions/2392766/multiline-strings-in-json) – Francisco Puga Feb 11 '18 at 20:06

2 Answers2

13

Turn on text wrapping in your editor / IDE.

Word wrap MSDN

JSON isn't JavaScript, it's data. It doesn't make sense to screw around with your data integrity for this. Enabling word wrap / configuring your editor to pretty-print JSON are better options. I personally prefer sublime text 3 for working with it.

cchamberlain
  • 17,444
  • 7
  • 59
  • 72
0

The JSON syntax doesn't allow for "multiline" strings as such. You'll just have to live with long lines or, if possible, make it an array of strings on separate lines which you then join with \n on the receiving side.

damd
  • 6,116
  • 7
  • 48
  • 77
  • 1
    I think this answer confuses multi-line strings, i.e. strings containing newline characters, with the actual question, which is how to make long strings in JSON more readable by making the JSON representation of the string span onto multiple lines in the JSON file. There are 2 very different concepts. – JoelFan Sep 02 '20 at 19:47