hdk-assemblyscript icon indicating copy to clipboard operation
hdk-assemblyscript copied to clipboard

Build a way to easily parse JSON strings into separate params

Open Connoropolous opened this issue 7 years ago • 19 comments

Connoropolous avatar Sep 25 '18 13:09 Connoropolous

To address this issue I have started a new repo (https://github.com/willemolding/asm-json-parser)

willemolding avatar Sep 26 '18 23:09 willemolding

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

MaxGraey avatar Sep 27 '18 14:09 MaxGraey

Both of those are great news @MaxGraey!

Connoropolous avatar Sep 27 '18 14:09 Connoropolous

I could start implementing JSON.parse and JSON.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

willemolding avatar Sep 30 '18 01:09 willemolding

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.

MaxGraey avatar Sep 30 '18 02:09 MaxGraey

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?

Connoropolous avatar Oct 03 '18 01:10 Connoropolous

also ping @maackle get in on this thread

Connoropolous avatar Oct 03 '18 01:10 Connoropolous

Since this relates to AS I opened an issue on the repo

https://github.com/AssemblyScript/assemblyscript/issues/292

willemolding avatar Oct 03 '18 02:10 willemolding

Yeah, I saw. So as I understand you required JSON.parse at first and JSON.stringify is not important for you right now?

MaxGraey avatar Oct 03 '18 23:10 MaxGraey

We require both actually. I guess I expect parse to be a much more challenging problem

willemolding avatar Oct 04 '18 00:10 willemolding

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

MaxGraey avatar Oct 05 '18 01:10 MaxGraey

BTW, if anyone is interested in BSON decoding/encoding in WebAssembly – check out https://github.com/nearprotocol/assemblyscript-bson

vgrichina avatar Dec 10 '18 02:12 vgrichina

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).

vgrichina avatar Jan 07 '19 08:01 vgrichina

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 avatar Jan 09 '19 01:01 vgrichina

@vgrichina could your implementation be used here or does it need to be integrated into assemblyscript for the project to proceed?

nickredmark avatar Feb 28 '19 07:02 nickredmark

@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.

vgrichina avatar Feb 28 '19 09:02 vgrichina

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?

nickredmark avatar Feb 28 '19 09:02 nickredmark

@vgrichina actually working on another project called NEAR Protocol. @nmaro you should addressed your question to Holochain team

MaxGraey avatar Feb 28 '19 09:02 MaxGraey

@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.

vgrichina avatar Feb 28 '19 20:02 vgrichina