Closed padi-g closed 11 months ago
Hey @padig, Thanks for creating the issue! It prompted me to update the readme. I've included the conversion of an array data type from motoko to JSON and vice versa.
The important thing is to define the data type and ensure it is an exact match to the equivalent data type in motoko.
For example, the createdOn
field stores a date timestamp but in motoko, it is recognized as a Text
From this example, it seems like the data type is:
type Record = {
parentNonprofits: [Text];
userId: Text;
giverEmailId: Text:
giveId: Text;
createdOn: Text;
feathersAmount: Nat;
giverId: Text;
projected: Text;
};
let #ok(blob) = JSON.fromText(jsonObj.data, null);
let records: ?[Record] = from_candid(blob);
Hi there, thanks a ton for this library! With my use case being a bit more complicated, I was wondering if you could update the sample to demonstrate how to convert a JSON payload of the following form to an array in motoko.
JSON payload -
I expect to be able to process it something like
records.add(jsonObj.data)
where records is a buffer or list data structure containing my custom type.Essentially, how do I process a JSON array using this library and get an array/list/buffer object in motoko?