guettli guettli - 4 months ago 17
JSON Question

Text based data format which supports multiline strings

I search a text based data format which supports multiline strings.

JSON does not allow multiline strings:

>>> import json
>>> json.dumps(dict(text='first line\nsecond line'))
'{"text": "first line\\nsecond line"}'

My desired output:

{"text": "first line
second line"}

This question is about input and output. The data format should be editable with a editor like vi, emacs or notepad.

I don't care if simple quotes
or tripple quotes (like in Python)
get used.

Is there a easy for human beings readable textual data interchange format which supports this?

Use case

I want to edit data with multiline strings with
. This is not fun, if the data is in json format.


I think you should consider YAML format. It supports block notation which is able to preserve newlines like this

data: |
   There once was a short man from Ealing
   Who got on a bus to Darjeeling
       It said on the door
       "Please don't spit on the floor"
   So he carefully spat on the ceiling

Also there is a lot of parsers for any kind of programming languages including python (i.e pyYaml).

Also there is a huge advantage that any valid JSON is YAML.