# JLD2 type compatibility

**URL:** <https://discourse.julialang.org/t/jld2-type-compatibility/77684>\
**Category:** Data\
**Tags:** jld2\
**Created:** [March 10, 2022, 1:15pm UTC](https://discourse.julialang.org/t/jld2-type-compatibility/77684 "2022-03-10T13:15:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alessio\_Bellisomi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alessio_bellisomi/32/12525_2.png) [@Alessio\_Bellisomi](https://discourse.julialang.org/u/Alessio_Bellisomi)\
**Post date:** [March 10, 2022, 1:15pm UTC](https://discourse.julialang.org/t/jld2-type-compatibility/77684/1 "2022-03-10T13:15:47Z")

</div>

I am using JLD2 to store some data in `struct` format, it works great. However some of the objects need to change, as I need to add more members.  
e.g.

```julia
struct A
    n::Int
    a::String
end

```

might become

```julia
struct A
    n::Int
    a::String
    b::String
end

```

when I read an old object with the new code it gives me this warning:

```julia
┌ Warning: saved type A is missing field b in workspace type; reconstructing 
└ @ JLD2 C:\.julia\packages\JLD2\k9Gt0\src\data\reconstructing_datatypes.jl:152

```

this is fine, the behavior is described here:  
[https://github.com/JuliaIO/JLD2.jl/blob/master/docs/src/advanced.md](https://github.com/JuliaIO/JLD2.jl/blob/master/docs/src/advanced.md)

However I am not sure how the proposed type remapping with `typemap` could help me: I would like to be able to load the old object in the new format but providing a default for eventual new properties.  
I remember with JLD I was used to leverage on features like `JLD.readas` and `JLD.translate`, is there anything similar with JLD2?

---

<div class="post-metadata">

**Author:** ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)\
**Post date:** [March 11, 2022, 7:40am UTC](https://discourse.julialang.org/t/jld2-type-compatibility/77684/2 "2022-03-11T07:40:45Z")

</div>

Hi @Alessio_Bellisomi ,

you will have to do the conversion yourself after loading the dataset into the _old_ struct as described in the docs.

---

<div class="post-metadata">

**Author:** ![Alessio\_Bellisomi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alessio_bellisomi/32/12525_2.png) [@Alessio\_Bellisomi](https://discourse.julialang.org/u/Alessio_Bellisomi)\
**Post date:** [March 11, 2022, 12:37pm UTC](https://discourse.julialang.org/t/jld2-type-compatibility/77684/3 "2022-03-11T12:37:24Z")

</div>

Ok, I understand. Let’s assume I have a mix of files, some built in the old structure and some in the new one. Is there a way I can tell if the one I am loading needs conversion at runtime? thanks
