Appendix D. Using JSON formatting
JavaScript Object Notation (JSON) is an often-used way to format the data exchanged by apps in the HTTP request and response when using REST endpoints to communicate (figure D.1). Because REST endpoints are one of the most encountered ways to establish communication between apps, and JSON is the main way to format the data exchanged, understanding and knowing how to use JSON formatting is essential.
Figure D.1 When you implement business logic, it sometimes implies establishing communication between multiple apps. Most often, you use JSON to format the data the apps exchange. To implement and test your REST endpoints, you need to understand JSON.
Fortunately, JSON is easy to understand, and it only follows a few rules. First, you need to know that what you represent with JSON are object instances using their attributes. Like in the case of a Java class, the attributes are identified with names and hold values. You may say the object Product has an attribute name and an attribute price. An instance of the Product class assigns values to the attributes. For example, the name is “chocolate,” and the price is 5. If you want to represent this in JSON, you need to consider the following rules: