From the course: Build REST APIs with FastAPI
Unlock this course with a free trial
Join today to access over 24,200 courses taught by industry experts.
JSON encoding - Python Tutorial
From the course: Build REST APIs with FastAPI
JSON encoding
REST API works with JSON messages. JSON is another acronym. It stands for JavaScript Object Notation. And as the name suggests, JSON comes from JavaScript. So it has several types that are defined in the JSON protocol, and you can see them here on the right side. So we have an object. This is usually a Python dictionary. We have an array which is the equivalent of a Python list, a string which is like a str in Python, a number. And in JSON we have only one type of number. But in Python we have floats, we have integers, we have decimals, we have fractions, and maybe some other number types. We have true and false for the Boolean and null which is the None of Python. And there are types in Python that you cannot find in JSON, for example, a set or a tuple. And we'll talk about how you can encode them in JSON. Let's have a look at a JSON document. Here I have a request for starting a new ride. So the car_id is a string which is a Python str, and we have the latitude and the longitude…