I have this API that returns all data as string:
{
value: "35.2"
}
Yet I want to map it to astruct with the proper type
struct Data
vaue::Float16
end
How can I instruct JSON3 to do the conversion?
I have this API that returns all data as string:
{
value: "35.2"
}
Yet I want to map it to astruct with the proper type
struct Data
vaue::Float16
end
How can I instruct JSON3 to do the conversion?
Welcome Olivier,
You can put your code between double " ``` " to make it more readable.
You can convert it yourself :
input = JSON3.read(string_api) #you can add your relative path with "." notation i.e. JSON3.read(string_api).value
struct Data
value::Float16
end
#You can convert your input with "parse" function
output = Data(parse(Float16, input))
From the example in the docs:
using JSON3, StructTypes
j="""{"value": "35.2"}"""
struct Data
value::Float16
end
StructTypes.StructType(::Type{Data}) = StructTypes.Struct()
d=JSON3.read(j, Data; parsequoted=true)