Working with JSON data using a REST web server
The HTTP
package can also be used to expose Julia functions as a REST API, as we will see in this section. However, in order to tackle that, first, we need to know how to handle JSON data in Julia.
In the following examples, we’ll use the JSON3
package.
Using the JSON3 package
In particular, the JSON3
package is widely used by the Genie framework. It is focused on speed by providing the following methods:
JSON3.read
(the equivalent ofJSON.parse
) to read a JSON string into aJSON3.Array
(or aJSON3.Object
). This allows you to access data with indexing or by using the dot notation, along with very flexible transformation to struct formats.JSON3.write
which makes a JSON string.
Here is a code example that illustrates these two methods (see Chapter2\json_rest\json3_package.jl
):
using HTTP, JSON3 todos = Dict( # type is Dict{Int64, String} &...