0

I have a block of json that I want to initialize a string with and I want to keep the formatting but this doesn't work.

The json will be much larger than this but just looking for possibilities for assigment w/formatting?

private static final String whateverXXX ='{
    "phonetype":"N95",
        "cat":"WP"
}'; 
genxgeek
  • 13,109
  • 38
  • 135
  • 217

1 Answers1

2

Impossible. You cannot put pretty-print JSON in a Java source file, ie. a .java file.

The Java Language Specification, among other things, states the following about String literals

It is a compile-time error for a line terminator to appear after the opening " and before the closing matching ".

Consider putting it in a separate text file and reading it in your Java code.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724