Serializing composite type to json

json

#1

Hi,

i have a

type foo 
       id::String
   ..
end

How to I serialize this to JSON easily ?

Looking for

JSON.toJson(Foo("Hello"))

JSON.jl accepts dictionaries only :=(

Thanks a lot
Frank


#2

I have been using JSON to serialize composite types happily for a while. In my case it was immutable instead of type, though.

See this example. The output files are in the same folder.


#3

It works for me:

julia> using JSON

julia> type Foo
           a::String
           b::Float64
       end

julia> JSON.json(Foo("xyz",1.2))
"{\"a\":\"xyz\",\"b\":1.2}"

Deserialize composite type from JSON
#4

My apologies. I misread the documentation, assuming it worked only for dictionaries… THANKS


#5

There’s no substitute for just trying something to see if it works!