Are multi-line strings allowed in JSON?

前端 未结 9 1464
醉酒成梦
醉酒成梦 2020-11-22 04:21

Is it possible to have multi-line strings in JSON?

It\'s mostly for visual comfort so I suppose I can just turn word wrap on in my editor, but I\'m just kinda curious

9条回答
  •  悲哀的现实
    2020-11-22 04:34

    While not standard, I found that some of the JSON libraries have options to support multiline Strings. I am saying this with the caveat, that this will hurt your interoperability.

    However in the specific scenario I ran into, I needed to make a config file that was only ever used by one system readable and manageable by humans. And opted for this solution in the end.

    Here is how this works out on Java with Jackson:

    JsonMapper mapper = JsonMapper.builder()
       .enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS)
       .build()
    

提交回复
热议问题