# Add field to standard JSON serialization

**URL:** https://discourse.julialang.org/t/add-field-to-standard-json-serialization/45112
**Category:** General Usage
**Tags:** json
**Created:** [August 17, 2020, 2:31pm UTC](https://discourse.julialang.org/t/add-field-to-standard-json-serialization/45112 "2020-08-17T14:31:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Amval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amval/32/6217_2.png) [@Amval](https://discourse.julialang.org/u/Amval)
#### Post date: [August 17, 2020, 2:31pm UTC](https://discourse.julialang.org/t/add-field-to-standard-json-serialization/45112/1 "2020-08-17T14:31:48Z")

</div>

Hello,

I basically want to achieve what is explained in [this post](https://discourse.julialang.org/t/json-type-serialization/9794):

When calling `JSON.json` on an object, add a Pair `type => string(typeof(t))` for child types of a certain abstract type. A cpuple restrictions:

- I need to use the default `JSON` library.
- I don’t want to specify the `JSON.lower` method manually, just to expand on the standard serialization.

I have read the `JSON.jl` documentation, but it’s unclear to me on how I can achieve this.

Any ideas? Thank you in advance.

---

<div class="post-metadata">

### Author: ![Amval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amval/32/6217_2.png) [@Amval](https://discourse.julialang.org/u/Amval)
#### Post date: [August 17, 2020, 3:21pm UTC](https://discourse.julialang.org/t/add-field-to-standard-json-serialization/45112/2 "2020-08-17T15:21:24Z")

</div>

This seems like the simplest solution, not sure if it has downsides:

```julia
function JSON.lower(e::MyAbstractType)
    result = Dict()
    for field in fieldnames(typeof(e))
        push!(result, field => getfield(e, field))
    end
    push!(result, :type => string(typeof(e)))
end

```
