-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add export to .json option #81
Comments
I made these libs:
One issue with raw proto-to-json, in general, is that every wire-type can actually be several different scalar-types, so it's impossible to really guess the format, reliably. There are a few assumptions you can make to roughly get the value, but it will almost always be off on some fields:
Part of what is great about this tool is that it just shows the possible types, so you can guess by looking at it, but there is no way to automate that. Another issue is that JSON doesn't directly map to protobuf. For example, you can have a repeated field at the same level,
It cannot be described like this in JSON (invalid): {
"10": {
"1": 100,
"2": "https://example.org/cat.png"
},
"10": {
"1": 200,
"2": "https://example.org/dog.png"
}
} so you have to do things like make it an array: {
"10": [
{
"1": 100,
"2": "https://example.org/cat.png"
},
{
"1": 200,
"2": "https://example.org/dog.png"
}
]
} or some other schema (like a flat array with objects that have field-number in it.) I get around this in my libs, by trying to guess and using arrays if multiples are found, or just always use arrays (so they can be traversed in the same way every time.) I think it's very doable to get "json from raw protobuf" in at least a format that is readable, but these issues make a 1-to-1 translation impossible without the schema, at least automatically. You can use my tools to generate (an approximation) in JSON (using rawproto or rawprotoparse), or to protoquery individual fields (where you have to provide the type you expect) or use a custom traversal function (in rawprotoparse.) protoquery also has something I call a "tree" which is a root-message that can be traversed, like an AST, but it's less like a plain JSON object, and more of a description of the bytes all broken-down. I am currently working on protoquery, and I think I will end up merging these projects into 1 thing (so you can query, or try to get "best guess" JSON, or generate a guess at the proto SDL.) |
Can you add an option to export the output into a .json file, please?
The text was updated successfully, but these errors were encountered: