I am writing a script that converts from json to ndjson in Python and am pretty new to the language. The cloud environment we use doesn't make use of files, but rather input and output variables. I found this code elsewhere on the site in discussion of conversion and was wondering how to go about converting this from reading and writing files to instead using an input string variable that has json code within it and then saving the ndjson to a string variable?
The code in question:
import json
with open("results-20190312-113458.json", "r") as read_file:
data = json.load(read_file)
result = [json.dumps(record) for record in data]
with open('nd-proceesed.json', 'w') as obj:
for i in result:
obj.write(i+'\n')