This tutorial was built using Rust Version: 1.22.1
Most programming languages support
JSON as part of the core language by default. It’s an incredibly popular data format that is used in millions of different applications.
In this tutorial we’ll be looking at how you can effectively work with JSON objects within our own Rust based systems. In order to do this we’ll be creating a very simple REST API that will do a variety of different things with JSON objects.
In this tutorial we’ll be utilizing the
Serde crate which can be found here: serde.
Serde is an awesome framework which can
Deserialize objects into a huge range of data formats including:
In order to use this you will have to add the following to your
and then you will have to add this to your crate root:
If you have ever used
Golang then the concept of defining
struct’s that will represent our
Let’s take a look at how we can serialize a
struct to a
If we conversely wanted to deserialize our
JSON string and convert it back to a
Greeting then we could do the following:
Let’s now put this all together and try and create a simple REST api that will return a JSON response. This
JSON response will be serialized from the
resp variable that we will follow the
Hopefully you found this tutorial useful! If you did or require further assistance then please let me know in the comments section below or by tweeting me @Elliot_F.