Skip to content

Measurements are getting serialized incorrectly #375

@mmikhasenko

Description

@mmikhasenko

I like very much the JSON.jl package and use all the time for serializing/deserializing Julia object in human-readable format.

When writing Measurements object, it literarily prints ±, that makes JSON invalid. It cannot be read.

using Measurements
using JSON

begin
	open("test.json", "w") do io
		JSON.print(io, Dict("value" => 1.1 ± 3.3))
	end
	# 
	open("test.json") do io
		JSON.parse(io)
	end
end

throws,

Expected ',' here
 ...when parsing byte with value '194'

This using strings works correctly,

begin
	open("test.json", "w") do io
		JSON.print(io, Dict("value" => "1.1 ± 3.3"))
	end
	# 
	open("test.json") do io
		JSON.parse(io)
	end
end

Suggestion

Treat Measurements similar to complex numbers, writing val, and err field in Dict.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions