function to jsonize prophy structs - #23
Conversation
| ('dynamic', [ | ||
| [('re', 45), ('im', 55)] | ||
| ]), | ||
| ] |
There was a problem hiding this comment.
Please add tests for serializing pure python's list, dict and tuple also test empty arguments for each case. Check strings with unicode characters and bytes strings with non ASCII characters (e.g. with each of '\x00\x01\x0a\xaf\xff').
| return str(e) | ||
|
|
||
|
|
||
| def jsonize(struct_, ordered=True): |
There was a problem hiding this comment.
Did you give yaml a thought? It seems to be "best suited for configuration" [1], and this is rather configuration (schema/typesystem of messages) than data (actual message objects with values). It's a little lighter than json for human eyes, allows comments, but might be less popular in terms of available parsers, etc.
>>> print(json.dumps(data, indent=True))
{
"foo": {
"x": [
1,
2,
3
],
"y": "uhishfusd",
"z": 1203
}
}
>>> print(yaml.dump(data))
foo:
x: [1, 2, 3]
y: uhishfusd
z: 1203
Can you point out disadvantages of yaml that I fail to see while writing this? :)
There was a problem hiding this comment.
Good point. yaml is much more readable than json. I think the reason to implement such exporter is that JSON can be used in Java Script out of the box - while YML needs some external libraries. I think exposing methods for both would be nice.
There was a problem hiding this comment.
Yaml is nice, and good to have here. But since it seems so easy to change json-> yaml (yaml.dump(json_struct)), do we need anything in our library? That can be done externally on the flow...
There was a problem hiding this comment.
No it's not needed. Even @aurzenligl did it in this way in his example (yaml.dump(..)). However there is one reason to make custom yaml frontend: hidden fields. Comments in yaml could help avoiding a confusion. E.g. a unpopulated dynamic array is not rendered in such a json, inactive optional field as well. A comment mentioning that fact could be very desirable.
There was a problem hiding this comment.
If function aims at preparing data structures for further serialization in json/yaml, name: sanitize_* could be used. It doesn't mention serialization itself nor serialization format, but it suggests conforming to some stricter standard. Jsonize suggests making and returning json.
|
@mareklabonarski, where are we with this PR, would you like to have it in prophy, or should we close it? |
|
Please let me keep it open and come back to it once all higher priority things are done. |
No description provided.