Open UBCYujia opened 1 month ago
Thanks @UBCYujia ! Can you post a minimal reproducible example please?
Array of arrays at least seem ok:
julia> Pigeons.json(test = [[12, 12], [1, 2]])
"{\"test\" : [[12, 12], [1, 2]]}"
But indeed matrix would probably create parsing error:
julia> Pigeons.json(test = [1 2; 3 4])
"{\"test\" : [1 2; 3 4]}"
Converte the latter into the former?
Thanks for reporting this Yujia!
I wonder if we can just use the JSON.jl pkg.
Thank you for providing the examples! to add one more, this 3d example shows that for a high dimensional array, the lowest level should always be 1d vector. array3d = reshape(1:27, 3, 3, 3) //doesn't work array = [array3d[:, :, i] for i in 1:size(array3d, 3)] //doesn't work, vector of 2d vectors vector_of_vectors = [[[array3d[i, j, k] for k in 1:size(array3d, 3)] for j in 1:size(array3d, 2)] for i in 1:size(array3d, 1)] //works! vector of vectors of 1d vectors
Yes I tried JSON.jl and it works well with Pigeons!
Nice! I see that they dont support NamedTuples which is the way we use Pigeons.json. But they do support Dicts, so the one liner would be
Pigeons.json(; kwargs...) = JSON.json(Dict(pairs(kwargs)))
or something similar
actually this is enough
> myjson(; kwargs...) = JSON.json(kwargs)
> myjson(;a=1,b=2)
"{\"a\":1,\"b\":2}"
@UBCYujia would you mind creating a PR to fix this issue?
Sure! I can try to do that!
Thank you, and let us know if you have any questions on how to do that. I think Lucas did one earlier so he might be able to assist with the logistics parts of the procedure
Pigeons.json() creates correct form of json string when taking scalar or 1d array as input. However, when it comes to 2d or higher dimensional arrays, it creates invalid json string (missing comma or "]").