I'm not sure if this result is compliant with "jsonl" syntax, but it's a hack that might get towards a relevant outcome.
The primary trick is to treat each line of the input file as a separate JSON file upon export, then read that JSON back in from disk and treat as distinct jsonl lines.
I'm starting from a CSV that contains
hello, from, this, file
another, amazing, line, csv
last, line, of, file
The snippet below builds on another post.
import pandas
df = pandas.read_csv("myfile.csv", header=None)
file_to_write = ""
for index in df.index:
df.loc[index].to_json("row{}.json".format(index))
with open("row{}.json".format(index)) as file_handle:
file_content = file_handle.read()
file_to_write += file_content + "\n"
with open("result.jsonl","w") as file_handle:
file_handle.write(file_to_write)
The resulting .jsonl file contains
{"0":"hello","1":" from","2":" this","3":" file"}
{"0":"another","1":" amazing","2":" line","3":" csv"}
{"0":"last","1":" line","2":" of","3":" file"}
If the row indices are not desired, those could be removed from the .to_json() line of the Python snippet above.
a lot of attempts to hijack a common practice. Just append the JSON strings at the end of the file you want. That;s the whole point. You only need to read to the next newline to read a JSON document instead of reading the entire file.ndjson.orgappeared beforejsonlines.organd contained the same text as the historicaljson.orgsite, without having any relation to either Douglas Crockford or ECMAto_jsoncan write each row in a separate row if you useorient='records', lines=True. From to_json docs:If ‘orient’ is ‘records’ write out line delimited json format. Will throw ValueError if incorrect ‘orient’ since others are not list like.