Skip to content

Latest commit

 

History

History
60 lines (38 loc) · 1.6 KB

README.md

File metadata and controls

60 lines (38 loc) · 1.6 KB

Unmarshal

Unmarshalling parsed format dictionaries into Julia Objects

Build Status

Coverage Status

codecov.io

Installation: pkg> add Unmarshal

Basic Usage

This package has currently only been tested with unmarshalling of JSON objects, but the intention is to in future also test it for working on other data formats.

import Unmarshal

using JSON

input = "{ \"bar\": { \"baz\": 17 }, \"foo\": 3.14 }"

struct Bar
    baz::Int
end

struct Foo
    bar::Bar
end

Unmarshal.unmarshal(Foo, JSON.parse(input))
# Foo(Bar(17))
jstring = JSON.json(ones(Float64, 3))
#"[1.0,1.0,1.0]"

Unmarshal.unmarshal(Array{Float64}, JSON.parse(jstring))
#3-element Array{Float64,1}:
# [ 1.0 ; 1.0 ; 1.0 ]
using LazyJSON

#"[1.0,1.0,1.0]"

Unmarshal.unmarshal(Array{Float64}, JSON.parse(jstring))
#3-element Array{Float64,1}:
# [ 1.0 ; 1.0 ; 1.0 ]

Documentation

Unmarshal.unmarshal(MyType, parseOutput, verbose = false )

Builds on object of type :MyType from the dictionary produced by JSON.parse or now also LazyJSON.parse. Set verbose to true to get debug information about the type hierarchy being unmarshalled. This might be useful in tracking down mismatches between the JSON object and the Julia type definition.