Json file with measurement values?

I have a json file with measurement types- any idea how to read it back to julia?

ie: file looks like

S.json={
      "D":4.0 ± 0.2,
      "tspan":{"t0":0,"tf":100},
      "params":{
                      "p":20.0 ± 4.0,
                      "c":0.2 ± 0.04000000000000001
                      }
}
using Json
function processInputs(inputdata)
    println("Getting Input Parameters.")
    open(inputdata, "r") do g
        global allParams
        allParams=JSON.parse(g,inttype=Float64)  # parse and transform data
    end
    return allParams 
end

allparams=processInputs("S.json")

result in:

Getting Input Parameters.
Expected ‘,’ here
…when parsing byte with value ‘194’
error(::String) at ./error.jl:33
_error(::String, ::JSON.Parser.StreamingParserState{IOStream}) at /opt/julia/packages/JSON/ebvl3/src/Parser.jl:150
_error_expected_char(::UInt8, ::JSON.Parser.StreamingParserState{IOStream}) at /opt/julia/packages/JSON/ebvl3/src/Parser.jl:85
skip! at /opt/julia/packages/JSON/ebvl3/src/Parser.jl:82 [inlined]
parse_object(::JSON.Parser.ParserContext{Dict{String,Any},Float64}, ::JSON.Parser.StreamingParserState{IOStream}) at /opt/julia/packages/JSON/ebvl3/src/Parser.jl:229
parse_value(::JSON.Parser.ParserContext{Dict{String,Any},Float64}, ::JSON.Parser.StreamingParserState{IOStream}) at /opt/julia/packages/JSON/ebvl3/src/Parser.jl:168
#parse#2(::Type, ::Type{Float64}, ::Function, ::IOStream) at /opt/julia/packages/JSON/ebvl3/src/Parser.jl:427
(::getfield(JSON.Parser, Symbol("#kw##parse")))(::NamedTuple{(:inttype,),Tuple{DataType}}, ::typeof(JSON.Parser.parse), ::IOStream) at ./none:0
#50 at ./In[20]:5 [inlined]
#open#294(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::getfield(Main, Symbol("##50#51")), ::String, ::Vararg{String,N} where N) at ./iostream.jl:369
open at ./iostream.jl:367 [inlined]
processInputs(::String) at ./In[20]:3
top-level scope at none:0
eval at ./boot.jl:319 [inlined]
(::getfield(Distributed, Symbol("##164#166")){Module,Expr})() at ./task.jl:259

Stacktrace:
[1] sync_end(::Array{Any,1}) at ./task.jl:226
[2] remotecall_eval(::Module, ::Array{Int64,1}, ::Expr) at /opt/julia-1.0.0/share/julia/stdlib/v1.0/Distributed/src/macros.jl:207

4.0 ± 0.2 is not a valid JSON number – you may need to make a first pass over the file to escape those as strings to load it into Julia, then parse them to a value + error (or some more complex type) after that.

Thanks -
Excuse the ignorance -
What do you mean by escape as strings? If i cant read the file how would you accomplish the change of type?

Thanks!

A

Basically what that means is that you have to first deal with those numbers, possibly transforming them to string, so JSON can read them into Julia. When you have accomplished that, you have to figure out a way to transform them into an appropriate numerical type in Julia. It’s a more involved process,

I see that;s wat I thought-

the easier solution I think (workin on it) is to parse the text as tow arrays val and err read them as independent numbers and then bring back togetehr in julia-

Thanks for the help and guidance :slight_smile:
A