# Json file with measurement values?

**URL:** <https://discourse.julialang.org/t/json-file-with-measurement-values/25170>\
**Category:** Data\
**Created:** [June 11, 2019, 9:58pm UTC](https://discourse.julialang.org/t/json-file-with-measurement-values/25170 "2019-06-11T21:58:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alewolf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alewolf/32/9000_2.png) [@alewolf](https://discourse.julialang.org/u/alewolf)\
**Post date:** [June 11, 2019, 9:58pm UTC](https://discourse.julialang.org/t/json-file-with-measurement-values/25170/1 "2019-06-11T21:58:56Z")

</div>

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

ie: file looks like

```julia
S.json={
      "D":4.0 ± 0.2,
      "tspan":{"t0":0,"tf":100},
      "params":{
                      "p":20.0 ± 4.0,
                      "c":0.2 ± 0.04000000000000001
                      }
}

```

```julia
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

---

<div class="post-metadata">

**Author:** ![amellnik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amellnik/32/137_2.png) [@amellnik](https://discourse.julialang.org/u/amellnik)\
**Post date:** [June 11, 2019, 10:03pm UTC](https://discourse.julialang.org/t/json-file-with-measurement-values/25170/2 "2019-06-11T22:03:03Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![alewolf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alewolf/32/9000_2.png) [@alewolf](https://discourse.julialang.org/u/alewolf)\
**Post date:** [June 11, 2019, 10:06pm UTC](https://discourse.julialang.org/t/json-file-with-measurement-values/25170/3 "2019-06-11T22:06:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alejandromerchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alejandromerchan/32/10500_2.png) [@alejandromerchan](https://discourse.julialang.org/u/alejandromerchan)\
**Post date:** [June 11, 2019, 10:30pm UTC](https://discourse.julialang.org/t/json-file-with-measurement-values/25170/4 "2019-06-11T22:30:41Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![alewolf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alewolf/32/9000_2.png) [@alewolf](https://discourse.julialang.org/u/alewolf)\
**Post date:** [June 11, 2019, 10:32pm UTC](https://discourse.julialang.org/t/json-file-with-measurement-values/25170/5 "2019-06-11T22:32:31Z")

</div>

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 🙂  
A
