23

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

codesalsa
  • 882
  • 5
  • 18

3 Answers3

8

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

alex
  • 10,900
  • 15
  • 70
  • 100
  • 1
    `application/jsonlines+json` <-- the [json suffix](https://en.wikipedia.org/wiki/Media_type#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 '21 at 15:25
  • 2
    application/jsonlines helps directly with respect to AWS Sagemaker DeepAR Batch Transform. – Purnajyoti Bhaumik Jun 14 '22 at 16:58
7

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.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • Thanks, any other suggestion for storing structured data in a file? – codesalsa Aug 05 '18 at 01: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: https://pypi.org/project/jsv/. Very early stages on this idea. – akovner Feb 11 '19 at 20:57
  • 4
    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 '19 at 15:34
5

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.

Trenton
  • 11,678
  • 10
  • 56
  • 60