in src/sagemaker_xgboost_container/encoder.py [0:0]
def json_to_jsonlines(json_data):
"""Convert a json response to jsonlines.
:param json_data: json data (dict or json string)
:return: jsonlines encoded response (bytes)
"""
resp_dict = json_data if isinstance(json_data, dict) else json.loads(json_data)
if len(resp_dict.keys()) != 1:
raise ValueError("JSON response is not compatible for conversion to jsonlines.")
bio = io.BytesIO()
for value in resp_dict.values():
for entry in value:
bio.write(bytes(json.dumps(entry) + "\n", "UTF-8"))
return bio.getvalue()