10

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"

4
  • and you want to do this without inserting line break inside the json string? Commented May 14, 2015 at 7: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. Commented May 14, 2015 at 7:06
  • stackoverflow.com/questions/2392766/multiline-strings-in-json Commented May 14, 2015 at 7:08
  • Possible duplicate of Multiline strings in JSON Commented Feb 11, 2018 at 20:06

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

This implicitly answers the question.
wow, what a simple solution. Thanks!
In Visual Studio Code: Menu "View"->"Word Wrap" or Alt+Z
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.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.