Open Connoropolous opened 5 years ago
I could start implementing JSON.parse
and JSON.stringify
based on RapidJSON implementation after merged this PR.
btw AssemblyScript joined to Open Collective so anyone who want speedup developing AS сan this help now
Both of those are great news @MaxGraey!
I could start implementing
JSON.parse
andJSON.stringify
based on RapidJSON implementation after merged this PR
What is your plan for implementing JSON.parse? I figure since AS can't have an any type you would need a way to parse to populate a predefined class like serde_json::from_str in rust.
Or I guess you could parse the JSON directly in to a hash map
It could be parse to Map<string, AnyValue>
where AnyValue
is wrapper class which could store one of other values like null
, numbers, string and other Map. This approach is fully dynamic and not performant. Other option is add @serializable/@deserializable
class decorators (similar to #[derive(Serialize, Deserialize)] in Rust) which pre-generate serialize-deserialize methods for each class field statically. That approach more complicated and require extra changes from compiler side as well but should be much faster and handy.
hey @MaxGraey looks like you got that PR merged! We are getting serious now about moving forward on this... we are going to explore a couple different options, but we'd actually like whatever we do, or collaborate with you on, to become a contribution to Assemblyscript. What do you think?
also ping @maackle get in on this thread
Since this relates to AS I opened an issue on the repo
Yeah, I saw. So as I understand you required JSON.parse
at first and JSON.stringify
is not important for you right now?
We require both actually. I guess I expect parse to be a much more challenging problem
As I understand you require json parsing only for your internal stuffs like passing variable set of arguments from host to wasm method, right? Could you use protobuffer/flatbuffer for that? Which implement much simpler and don't require parsing at all
EDIT also more simpler way is implement PSON/BSON. PSON decoding even already implemented on AS: https://github.com/AssemblyScript/assemblyscript/tree/master/examples/pson
BTW, if anyone is interested in BSON decoding/encoding in WebAssembly – check out https://github.com/nearprotocol/assemblyscript-bson
I have also created encoder / decoder for JSON: https://github.com/nearprotocol/assemblyscript-json/
It doesn't support floats yet (though not hard to add) + can still be improved performance-wise and probably needs some edge case testing. Generally it implements grammar from http://json.org, so any unhandled cases would be only by mistake.
Let me know if there is anything missing.
P.S. You also will be able to generate bindings automatically, however current implementation only does BSON (see https://github.com/nearprotocol/assemblyscript/tree/master/tests/near-bindgen for example).
Bindings generation for JSON is also ready now: https://github.com/nearprotocol/assemblyscript/pull/12
However note that it's specific to our use case.
@vgrichina could your implementation be used here or does it need to be integrated into assemblyscript for the project to proceed?
@nmaro if you are talking about binding generation – it has to be integrated into compiler for now, but assemblyscript-json
package is usable as is.
Thanks. Perhaps the greater question is what would be needed for the development here to continue. Are you blocked by the assemblyscript project or are you prioritizing something else or do you need help?
@vgrichina actually working on another project called NEAR Protocol. @nmaro you should addressed your question to Holochain team
@nmaro the real answer is that you should just be using NEAR Protocol where we already handled serialization :-P
It's easy to get started – just go to http://studio.nearprotocol.com/, create project from one of the templates and press Run. You'll have an app running on our chain in like less than a minute.
To address this issue I have started a new repo (https://github.com/willemolding/asm-json-parser)