but that seems quite ugly to me. Moreover, line
emptyJson=JSON3.read(str)
prints {} in the output, so I should be able to use XYZ()=XYZ(0, {}).
I don’t understand why it doesn’t work and what would be the best code for what I am trying to achieve.
I have created simple REST microservice with GET/POST/DELETE. Structure XYZ represents structure of record in a database table.
Everything worked (and it was able to get/add/delete record from Postgres table) until I had to set 1 of the columns to Postgres type jsonb.
So I added that item “item” in the struct XYZ (my structure actually has more items/columns in the table than shown here, but those are now irrelevant).
And I am able to execute POST request successfully when I use that trick
So the real task is to map a Postgres jsonb type to something appropriate in Julia. For me it looks like to be String as the best match.
How about something like:
mutable struct XYZ
id::Int64
json::String
json_parsed::JSON3.Object
function XYZ( id::Int64, json::String )
new(id, json, JSON3.read(json) )
end
end
So, I suggest, that your XYZ struct and some other needed methods do the translation between the Postgres types json and/or jsonb. Does this makes sense to you? I am a bit brief in my explanation, I know, but I am not sure that I have hit the real problem you have. Perhaps someone else has solved this already.
If I am right, you may consider to change the headline, so it is clear, that it is about Postgres json/jsonb mapping to Julia.