-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
There is a possible improvement in b696398 in the way we convert markdown to JSON.
Bug:
If the value is empty (for example - identifier: ), the equivalent json will be
{
...
"identifier": "",
...
}
which is both ugly and nonstandard for JSON.
The convention would rather be to have no name/value pair at all or having the null value
Solution:
My improved code based on the actual one:
observations = []
record = dict()
for line in txt.split("\n")[2:]:
if line[:2] == "##":
print(line)
if len(record) != 0:
observations.append(record)
record = dict()
else:
if not line.strip()=="":
print(f'process "{line}"')
lhs, rhs = (line[2:].split(":"))
lhs = lhs.strip()
rhs = rhs.strip()
if rhs != ""
record[lhs] = rhs
else:
record[lhs] = NoneThe python None value will translate to null when using json.dumps()
One could also just drop the else statement and simply get no name/value pair for this line.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels