# Convert bytes to object

**URL:** <https://forum.dfinity.org/t/convert-bytes-to-object/4713>\
**Category:** Developers\
**Tags:** Functional-Programming, candid\
**Created:** [June 3, 2021, 9:23am UTC](https://forum.dfinity.org/t/convert-bytes-to-object/4713 "2021-06-03T09:23:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SvyatobatkoVlad](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/svyatobatkovlad/32/1988_2.png) [@SvyatobatkoVlad](https://forum.dfinity.org/u/SvyatobatkoVlad)\
**Post date:** [June 3, 2021, 9:23am UTC](https://forum.dfinity.org/t/convert-bytes-to-object/4713/1 "2021-06-03T09:23:15Z")

</div>

How to pass array of bytes to canister and convert those bytes to object in Motoko?  
Is there any example of this?

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [June 3, 2021, 9:37pm UTC](https://forum.dfinity.org/t/convert-bytes-to-object/4713/2 "2021-06-03T21:37:07Z")

</div>

I’d like to help, but I’m not sure I fully understand the question.

Is that passing an array of bytes from Javascript to Motoko or between canisters?

And what exactly do you have in mind when converting those bytes to an object? What sort of object?

---

<div class="post-metadata">

**Author:** ![SvyatobatkoVlad](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/svyatobatkovlad/32/1988_2.png) [@SvyatobatkoVlad](https://forum.dfinity.org/u/SvyatobatkoVlad)\
**Post date:** [June 5, 2021, 8:24pm UTC](https://forum.dfinity.org/t/convert-bytes-to-object/4713/3 "2021-06-05T20:24:42Z")

</div>

I want to transfer an array of bytes to a canister using the command “canister call mycanistr …” and then in the canister convert those bytes to a structure or object. For example, as in the Golang language “json.Unmarshal”

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [June 6, 2021, 4:10pm UTC](https://forum.dfinity.org/t/convert-bytes-to-object/4713/4 "2021-06-06T16:10:59Z")

</div>

As long as you are happy with the Candid serialization format, Motoko already does the marshalling and unmarshalling of structured data to bytes for you.

If you don’t want to use Candid, but want to have your own serialization format or implement another one, then we don’t have any examples of that, as far as I am aware, and you will need to roll your own marshalling and unmarshalling mechanism. Something along the line of Andrew Kennedy’s pickler combinators should translate nicely to Motoko,

> **[Functional Pearl: Pickler Combinators - Microsoft Research](https://www.microsoft.com/en-us/research/publication/functional-pearl-pickler-combinators/)**
>
> The tedium of writing pickling and unpickling functions by hand is relieved using a combinator library similar in spirit to the well-known parser combinators. Picklers for primitive types are combined to support tupling, alternation, recursion, and...

but perhaps you’ve got something else in mind.
