Measurements.jl icon indicating copy to clipboard operation
Measurements.jl copied to clipboard

Not printed correctly into JSON

Open mmikhasenko opened this issue 5 months ago • 5 comments

When printing a Measument to JSON, the resulting file in not valid due to ± sign.

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'

posted here https://github.com/JuliaIO/JSON.jl/issues/375

It might turn out not JSON problem, rather Measurements.jl problem, since JSON.jl does not have rules for customary objects.

mmikhasenko avatar Jul 11 '25 09:07 mmikhasenko

I guess you want to define a custom JSON.lower method. But deserialisation is up to the reader, since it's just interpreting a dictionary.

giordano avatar Jul 11 '25 09:07 giordano

it's not clear to me how to make two package working together without making one to depend on the other.

I want that JSON.print write a valid JSON file, or throw an error if it cannot.

mmikhasenko avatar Jul 11 '25 14:07 mmikhasenko

it's not clear to me how to make two package working together without making one to depend on the other.

https://pkgdocs.julialang.org/v1/creating-packages/#Conditional-loading-of-code-in-packages-(Extensions)

giordano avatar Jul 11 '25 14:07 giordano

Do you suggest it for Measurements.jl?

mmikhasenko avatar Jul 11 '25 14:07 mmikhasenko

Pkgextensions are symmetrical, can be hosted in any of the trigger packages.

giordano avatar Jul 11 '25 14:07 giordano