# Unmarshaling JSON based on a type defined in the JSON object

**URL:** <https://discourse.julialang.org/t/unmarshaling-json-based-on-a-type-defined-in-the-json-object/31170>\
**Category:** General Usage\
**Tags:** json\
**Created:** [November 17, 2019, 8:10am UTC](https://discourse.julialang.org/t/unmarshaling-json-based-on-a-type-defined-in-the-json-object/31170 "2019-11-17T08:10:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![watzon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/watzon/32/11337_2.png) [@watzon](https://discourse.julialang.org/u/watzon)\
**Post date:** [November 17, 2019, 8:10am UTC](https://discourse.julialang.org/t/unmarshaling-json-based-on-a-type-defined-in-the-json-object/31170/1 "2019-11-17T08:10:37Z")

</div>

I asked a similar question in the gitter chat, but I figured I’d ask here too. Basically this is the issue:

I am attempting to write a Julia wrapper for [TDLib](https://github.com/tdlib/td), and more specifically for the libtdjson portion of the library. Basically it acts as a JSON interface to Telegram. The JSON objects it sends come in the format

```json
{
  "@type": "objectType",
  "other_prop": "value",
  "other_object": {
    "@type": "someOtherObject"
  }
}

```

where every object has a `@type` field that should correspond to a struct. So for the above object I’d have

```julia
struct ObjectType
  other_prop::String
  other_object::SomeOtherObject
end

struct SomeOtherObject
end

```

In reality there are more than 770 types that TDLib defines, all of which will be auto-generated based on the [schema](https://core.telegram.org/schema). So my question is: is there an existing library or built in method capable of handling a situation like this? Or if not, what would be the best course of action to make deserializing these types as painless as possible. I am new to Julia, so any pointers would be helpful.
