17

I want to know what Content-Type to set for JSON lines (http://jsonlines.org/)?

I tried searching. Its not really application/json as the entire content is not JSON (each line is).

Thanks

3 Answers 3

5

As per https://github.com/wardi/jsonlines/issues/9, there is no official mime type, but a convention of application/x-ndjson. Or application/x-jsonlines. Note that this issue has been sitting there since 2015, which might suggest that jsonlines is not exactly catching fire.

3
  • Thanks, any other suggestion for storing structured data in a file?
    – codesalsa
    Aug 5, 2018 at 1:08
  • @codesalsa At the risk of self-promotion, I wrote a python package called jsv (json separated values) meant to store structured data with the expressiveness of json lines, but the compactness of csv. It is available here: pypi.org/project/jsv. Very early stages on this idea.
    – akovner
    Feb 11, 2019 at 20:57
  • 3
    The jsonlines format is widely used, just not by name (because it's such an obvious idea) - JSON based log formats (such as in Docker, JournalD, etc.), streaming JSON apis, etc.
    – TomW
    Jul 16, 2019 at 15:34
4

I have the server return text/plain; charset=utf8 for JSON Lines files. As @bmargulies says, application/x-ndjson has limited support. At least with text/plain users can see the data in their browser (rather than being shown a download/save as dialog). Setting the charset explicitly prevents random "corruption" by (un)helpful user agents.

3

JSON lines is supported by some AWS services and they use application/jsonlines content type.

1
  • application/jsonlines+json <-- the json suffix is technically a lie, but it encourages Chrome to display the file as text/plain. Otherwise it downloads as octet/stream.
    – Bob Stein
    Oct 12, 2021 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.