JSON at Work

Book description

JSON is becoming the backbone for meaningful data interchange over the internet. This format is now supported by an entire ecosystem of standards, tools, and technologies for building truly elegant, useful, and efficient applications. With this hands-on guide, author and architect Tom Marrs shows you how to build enterprise-class applications and services by leveraging JSON tooling and message/document design.

JSON at Work provides application architects and developers with guidelines, best practices, and use cases, along with lots of real-world examples and code samples. You’ll start with a comprehensive JSON overview, explore the JSON ecosystem, and then dive into JSON’s use in the enterprise.

  • Get acquainted with JSON basics and learn how to model JSON data
  • Learn how to use JSON with Node.js, Ruby on Rails, and Java
  • Structure JSON documents with JSON Schema to design and test APIs
  • Search the contents of JSON documents with JSON Search tools
  • Convert JSON documents to other data formats with JSON Transform tools
  • Compare JSON-based hypermedia formats, including HAL and jsonapi
  • Leverage MongoDB to store and access JSON documents
  • Use Apache Kafka to exchange JSON-based messages between services

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Audience, Assumptions, and Approach
    2. What Does “At Work” Mean?
    3. What You’ll Learn
    4. What You’ll Work With
    5. Who This Book Is Not For
    6. Organization
      1. Part I, JSON Overview and Platforms
      2. Part II, The JSON Ecosystem
      3. Part III, JSON in the Enterprise
      4. Appendices
    7. Code Examples
    8. O’Reilly Safari
    9. How to Contact Us
    10. Acknowledgments
  2. I. JSON Overview and Platforms
  3. 1. JSON Overview
    1. JSON Is a Standard
    2. A Brief Sample
    3. Why JSON?
    4. Core JSON
      1. JSON Data Types
      2. JSON Value Types
      3. JSON Versions
      4. JSON Comments
      5. JSON File and MIME Type
      6. JSON Style Guidelines
    5. Our Example—MyConference
      1. Our Technical Stack
      2. Our Architectural Style—noBackEnd
      3. Model JSON Data with JSON Editor Online
      4. Generate Sample JSON Data with JSON Generator
      5. Create and Deploy a Stub API
    6. What We Covered?
    7. What’s Next?
  4. 2. JSON in JavaScript
    1. Node.js Setup
    2. JSON Serialization/Deserialization with JSON.stringify() and JSON.parse()
      1. The JSON Stringifier/Parser Object
      2. JSON Serialization with Simple JavaScript Data Types
      3. JSON Serialization with an Object and toJSON()
      4. JSON Deserialization Using eval()
      5. JSON Deserialization with an Object and JSON.parse()
    3. JavaScript Objects and JSON
      1. Node REPL
      2. Where to Learn More About JavaScript Objects
    4. Unit Testing with a Stub API
      1. Unit Test Style—TDD and BDD
      2. Just Enough Unit Testing with Mocha and Chai
      3. Setting Up the Unit Test
      4. Unirest
      5. Test Data
      6. Speakers Unit Test
    5. Building a Small Web Application
      1. Yeoman
      2. Iteration 1—Generate a Web Application with Yeoman
      3. Iteration 2—Make an HTTP Call with jQuery
      4. Iteration 3—Consume Speaker Data from a Stub API and Use a Template
    6. How to Go Deeper with JavaScript
    7. What We Covered
    8. What’s Next?
  5. 3. JSON in Ruby on Rails
    1. Ruby on Rails Setup
    2. Ruby JSON Gems
    3. JSON Serialization/Deserialization with MultiJson
      1. The MultiJson Object
      2. JSON Serialization/Deserialization with Simple Ruby Data Types
      3. JSON Deserialization with Objects and MultiJson
      4. A Word on Camel Casing and JSON
      5. JSON Serialization with Objects and ActiveSupport
      6. JSON Deserialization with Objects and ActiveSupport
    4. Unit Testing with a Stub API
      1. Just Enough Unit Testing with Minitest
      2. Setting Up the Unit Test
      3. Test Data
      4. JSON and Minitest Testing with APIs
      5. Speakers Unit Test
      6. Further Reading on Ruby and Minitest
      7. What Is Missing in the Unit Tests?
    5. Build a Small Web API with Ruby on Rails
      1. Choose a JSON Serializer
      2. speakers-api-1—Create an API with Camel-Cased JSON
      3. speakers-api-2—Create an API that Customizes the JSON Representation
      4. Further Reading on Rails and Rails-based APIs
    6. What We Covered
    7. What’s Next?
  6. 4. JSON in Java
    1. Java and Gradle Setup
    2. Gradle Overview
    3. Just Enough Unit Testing with JUnit
    4. Java-Based JSON Libraries
    5. JSON Serialization/Deserialization with Jackson
      1. Serialization/Deserialization with Simple Java Data Types
      2. Serialization/Deserialization with Java Objects
    6. Unit Testing with a Stub API
      1. Test Data
      2. JSON and JUnit Testing with APIs
    7. Build a Small Web API with Spring Boot
      1. Create the Model
      2. Create the Controller
      3. Register the Application
      4. Write the Build Script
      5. Deploy the API
      6. Test the API with Postman
    8. What We Covered
    9. What’s Next?
  7. II. The JSON Ecosystem
  8. 5. JSON Schema
    1. JSON Schema Overview
      1. What Is JSON Schema?
      2. Syntactic Versus Semantic Validation
      3. A Simple Example
      4. JSON Schema on the Web
      5. Why JSON Schema?
      6. My Journey with JSON Schema
      7. The Current State of the JSON Schema Standard
      8. JSON Schema and XML Schema
    2. Core JSON Schema—Basics and Tooling
      1. JSON Schema Workflow and Tooling
      2. Core Keywords
      3. Basic Types
      4. Numbers
      5. Arrays
      6. Enumerated Values
      7. Objects
      8. Pattern Properties
      9. Regular Expressions
      10. Dependent Properties
      11. Internal References
      12. External References
      13. Choosing Validation Rules
    3. How to Design and Test an API with JSON Schema
      1. Our Scenario
      2. Model a JSON Document
      3. Generate a JSON Schema
      4. Validate the JSON Document
      5. Generate Sample Data
      6. Deploy a Stub API with json-server
      7. Final Thoughts on API Design and Testing with JSON Schema
    4. Validation Using a JSON Schema Library
    5. Where to Go Deeper with JSON Schema
    6. What We Covered
    7. What’s Next?
  9. 6. JSON Search
    1. Why JSON Search?
    2. JSON Search Libraries and Tools
      1. Honorable Mention
      2. What to Look For
    3. Test Data
    4. Setting Up Unit Tests
    5. Comparing JSON Search Libraries and Tools
      1. JSONPath
      2. JSON Pointer
      3. jq
    6. JSON Search Library and Tool Evaluations—The Bottom Line
    7. What We Covered
    8. What’s Next?
  10. 7. JSON Transform
    1. Types of JSON Transformation
    2. What to Look For in a JSON Transform Library
    3. Test Input Data
    4. JSON-to-HTML Transformation
      1. Target HTML Document
      2. Mustache
      3. Handlebars
      4. JSON-to-HTML Transformation Evaluations—The Bottom Line
    5. JSON-to-JSON Transform
      1. The Issues
      2. JSON-to-JSON Transform Libraries
      3. Honorable Mention
      4. Target JSON Output
      5. JSON Patch
      6. JSON-T
      7. Mustache
      8. Handlebars
      9. JSON-to-JSON Transformation Evaluations—The Bottom Line
    6. JSON-XML Transformation
      1. JSON-XML Transformation Conventions
      2. The Issues with JSON-XML Transformation Conventions
      3. XML-JSON Transform—The Bottom Line
      4. JSON-XML Transformation Unit Test
    7. What We Covered
    8. What’s Next?
  11. III. JSON in the Enterprise
  12. 8. JSON and Hypermedia
    1. Comparing Hypermedia Formats
      1. Defining Key Terms
      2. My Opinion on Hypermedia
      3. Siren
      4. JSON-LD
      5. Collection+JSON
      6. json:api
      7. HAL
    2. Conclusions on Hypermedia
    3. Recommendations for Working with Hypermedia
    4. Practical Issues with Hypermedia
    5. Testing with HAL in the Speakers API
      1. Test Data
      2. HAL Unit Test
    6. Server-Side HAL
    7. Going Deeper with Hypermedia
    8. What We Covered
    9. What’s Next?
  13. 9. JSON and MongoDB
    1. What About BSON?
    2. MongoDB Setup
    3. MongoDB Server and Tools
    4. MongoDB Server
    5. Importing JSON into MongoDB
    6. MongoDB Command Shell
      1. Basic CRUD with mongo
    7. Exporting from MongoDB to a JSON Document
    8. What About Schema?
    9. RESTful API Testing with MongoDB
      1. Test Input Data
      2. Providing a RESTful Wrapper for MongoDB
    10. What We Covered
    11. What’s Next?
  14. 10. JSON Messaging with Kafka
    1. Kafka Use Cases
    2. Kafka Concepts and Terminology
    3. The Kafka Ecosystem—Related Projects
    4. Kafka Environment Setup
      1. Why Do I Need ZooKeeper?
    5. Kafka Command-Line Interface (CLI)
      1. How to Publish a JSON Message with the CLI
      2. Start ZooKeeper
      3. Start Kafka
      4. Create a Topic
      5. List Topics
      6. Start a Consumer
      7. Publish a JSON Message
      8. Consume a JSON Message
      9. Clean Up and Shut Down Kafka
    6. Kafka Libraries
    7. End-to-End Example—Speaker Proposals at MyConference
      1. Test Data
      2. Architecture Components
      3. Set Up the Kafka Environment
      4. Set Up Fake Email Server and Client—MailCatcher
      5. Set Up Node.js Project Environment
      6. Speaker Proposal Producer (Send Speaker Proposals)
      7. Proposal Reviewer (Consumer/Producer)
      8. Speaker Notifier (Consumer)
      9. Review Notification Email Messages with MailCatcher
    8. What We Covered
  15. A. Installation Guides
    1. Install JSON Tools in the Browser
      1. Install JSONView in Chrome and Firefox
      2. JSONLint
      3. JSON Editor Online
      4. Install Postman
    2. Install Node.js
      1. Install Node.js on macOS and Linux with NVM
      2. Install Node.js on Windows
      3. Uninstall Node.js
      4. Install Yeoman
      5. Install npm Modules
    3. Install Ruby on Rails
      1. Install Rails on macOS and Linux
      2. Install Rails on Windows
      3. Install Ruby Gems
    4. Install MongoDB
    5. Install the Java Environment
      1. Install Java SE
      2. Install Gradle
    6. Install jq
    7. Install cURL
      1. Install cURL on macOS
      2. Install cURL on Linux
      3. Install cURL on Windows
    8. Install Apache Kafka
      1. Install Kafka on macOS
      2. Install Kafka on UNIX
      3. Install Kafka on Windows
    9. References
  16. B. JSON Community
  17. Index

Product information

  • Title: JSON at Work
  • Author(s): Tom Marrs
  • Release date: July 2017
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449358327