# Way to "encode" an object?

**URL:** <https://discourse.julialang.org/t/way-to-encode-an-object/26465>\
**Category:** New to Julia\
**Created:** [July 17, 2019, 2:44pm UTC](https://discourse.julialang.org/t/way-to-encode-an-object/26465 "2019-07-17T14:44:05Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![dawbarton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dawbarton/32/215461_2.png) [@dawbarton](https://discourse.julialang.org/u/dawbarton)\
**Post date:** [July 17, 2019, 2:58pm UTC](https://discourse.julialang.org/t/way-to-encode-an-object/26465/4 "2019-07-17T14:58:42Z")

</div>

If you want a string output, just combine the previously mentioned serialization with base64 encoding.

```julia
julia> using Serialization, Base64

julia> test = base64encode(serialize, (a="Hello World",b=2))
"N0pMBwQAAAA0EAEKTmFtZWRUdXBsZR9OAQRNYWlum0QCAAAAFAJmZxBTH04BBE1haW6bRAIAAAAAIQAIIQtIZWxsbyBXb3JsZOE="

julia> deserialize(IOBuffer(base64decode(test)))
(a = "Hello World", b = 2)

```

Just be aware that the serialization format isn’t designed for long-term storage (i.e, it might change in the future, though probably not any time soon). Also, there are potential security issues, for example [Document security properties of Serialization · Issue #32601 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/32601) (but this is also a problem for JLD2: [Security issue: Type confusion, convert called during deserialization · Issue #117 · JuliaIO/JLD2.jl · GitHub](https://github.com/JuliaIO/JLD2.jl/issues/117)).

---

_[View the full topic](https://discourse.julialang.org/t/way-to-encode-an-object/26465)._
