pythonjsonpython-3.xgoogle-cloud-platformmulti-document

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}})

Solution

  • 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.