I would like to use type hinting for my python functions.
One takes Newline Delimited JSON as input and another has NDJSON as output. Is there a specific type hint for JSON or NDJSON?
Or is it just a string? What options do I have here for type hinting?
Example of my "string" looks as follows:
{"Employee": "Sander", "ID": 3}
{"Employee": "Someone else", "ID": 5}
Example of my function:
def get_ndjson(employees_dicts_list) -> NDJSON:
employee_data = [json.dumps(employee) for employee in employees_dicts_list]
return "\n".join(employee_data)
From the json.dumps
documentation:
Serialize
obj
to a JSON formattedstr
using this conversion table.
So your employee_data
is a list
of str
and the returned value is just a str
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.