Format JSON to one line per input


I’m trying to make my json compatible with Google ML, which after some searching means having one line per input instance (Input instances are not in JSON format.)

How can I change my code to have only one line per instance? (img variable is the image I encoded to base64)

json.dumps({"inputs": {"b64": img}})
Asked By: K41F4r



The format you’re referring to is called json-lines (.jl for a file extension).
You can use the json-lines python package in place of json.dumps.

Answered By: Teodor Ivanov