# \[ANN\] JSON3.jl - Yet another JSON package for Julia

**URL:** <https://discourse.julialang.org/t/ann-json3-jl-yet-another-json-package-for-julia/25625>\
**Category:** Package Announcements\
**Created:** [June 24, 2019, 8:31pm UTC](https://discourse.julialang.org/t/ann-json3-jl-yet-another-json-package-for-julia/25625 "2019-06-24T20:31:10Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![Martin\_Florek](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@Martin\_Florek](https://discourse.julialang.org/u/Martin_Florek)\
**Post date:** [September 16, 2020, 2:56pm UTC](https://discourse.julialang.org/t/ann-json3-jl-yet-another-json-package-for-julia/25625/21 "2020-09-16T14:56:40Z")

</div>

Something new in this regard, please? How to write a matrix correctly? Thx

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [September 16, 2020, 5:14pm UTC](https://discourse.julialang.org/t/ann-json3-jl-yet-another-json-package-for-julia/25625/22 "2020-09-16T17:14:55Z")

</div>

If you structure is mutable, you can use reshape:

```julia
julia> mutable struct A
         x  
       end

julia> using StructTypes

julia> StructTypes.StructType(::Type{A}) = StructTypes.Struct()

julia> using JSON3

julia> a = A(rand(3,3))

julia> s = JSON3.write(a)

julia> sread = JSON3.read(s,A)

julia> sread.x = reshape(sread.x,3,3)
3×3 Array{Any,2}:
 0.89818 0.503697 0.0568256
 0.424703 0.505502 0.570105
 0.385958 0.721714 0.46072

```

If the structure is not mutable, then what I do is to reshape the vectors read saving them in new arrays, and then I initialize a new structure with the data reshaped.

---

<div class="post-metadata">

**Author:** ![Martin\_Florek](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@Martin\_Florek](https://discourse.julialang.org/u/Martin_Florek)\
**Post date:** [September 17, 2020, 8:27am UTC](https://discourse.julialang.org/t/ann-json3-jl-yet-another-json-package-for-julia/25625/23 "2020-09-17T08:27:27Z")

</div>

Thanks @leandromartinez98 for the tips, but I’d rather adjust the structure attribute of Matrix to Vector (structure is _immutable_).  
Now I have a question how to write/read `Dates.Period`?

```julia
mutable struct Foo
  samplingPeriod::Period
end
JSON3.StructType(::Type{<:Foo}) = JSON3.Struct()
JSON3.StructType(::Type{<:Period}) = JSON3.StringType()

str = JSON3.write(Foo(Second(3600)))
"{\"samplingPeriod\":\"3600 seconds\"}"

o = JSON3.read(str, Foo)
ERROR: MethodError: no method matching Period(::String)

```

Do I have to overload the `Period` method or is there a more elegant way? Any experience? Thanks.

---

<div class="post-metadata">

**Author:** ![DataPsycho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datapsycho/32/16891_2.png) [@DataPsycho](https://discourse.julialang.org/u/DataPsycho)\
**Post date:** [September 19, 2020, 8:38pm UTC](https://discourse.julialang.org/t/ann-json3-jl-yet-another-json-package-for-julia/25625/24 "2020-09-19T20:38:00Z")

</div>

I am having an issue when serializing If someone can help on this regards:

> [@JSON3 Package: ArgumentError: invalid JSON at byte .... : InvalidChar?](https://discourse.julialang.org/t/json3-package-argumenterror-invalid-json-at-byte-invalidchar/46933):
>
> Suppose I have two Structs one for Tweet and another for Author of the tweet as follows: struct User id::Union{Int64, Nothing} id\_str::Union{String, Nothing} created\_at::Union{String, Nothing} name::Union{String, Nothing} screen\_name::Union{String, Nothing} location::Union{String, Nothing} statuses\_count::Union{Int64, Nothing} followers\_count::Union{Int64, Nothing} description::Union{String, Nothing} profile\_image\_url::Union{String, Nothing} end struct T…

[Previous page](https://discourse.julialang.org/t/ann-json3-jl-yet-another-json-package-for-julia/25625.md?page=1)
