Chapter 6. Working with JSON in Groovy

In this chapter, we will cover:

  • Parsing JSON messages with JsonSlurper
  • Constructing JSON messages with JsonBuilder
  • Modifying JSON messages
  • Validating JSON messages
  • Converting JSON message to XML
  • Converting JSON message to Groovy Bean
  • Using JSON to configure your scripts

Introduction

JSON (JavaScript Object Notation) (http://www.json.org/) is a data interchange format, similar in scope to XML or CSV. It uses a very lightweight serialization form and works very well for exchanging data between a web client (a browser) and a remote server, but it is not limited to only that.

JSON is also a subset of the object literal notation of JavaScript. Being a subset of JavaScript implies that a JSON payload can be processed by ...

Get Groovy 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.