|
@@ -16,16 +16,16 @@ object JsonSection extends FlatSpec with Matchers with definitions.Section { |
|
|
|
|
|
import JsonHelpers._ |
|
|
|
|
|
/** Json is the circe data type representing a Json object. It's very useful to be familiar with this data type since |
|
|
/** `Json` is the circe data type representing a JSON object. It's very useful to be familiar with this data type since |
|
|
* it's how circe models the base type we want to address. |
|
|
* |
|
|
* To begin, let's briefly talk about the shape of every Json object. It's basically semi-structured data built on |
|
|
* To begin, let's briefly talk about the shape of every `Json` object. It's basically semi-structured data built on |
|
|
* top of key-value pairs. These key-value pairs have a specific shape: |
|
|
* - keys are strings. |
|
|
* - values can be multiple types. |
|
|
* |
|
|
* Next, to model a real json object, we need to support different data types in the value field. For this purpose, |
|
|
* we have different available methods so we can create a Json object from different source data types. Some examples |
|
|
* Next, to model a real JSON object, we need to support different data types in the value field. For this purpose, |
|
|
* we have different available methods so we can create a `Json` object from different source data types. Some examples |
|
|
* of these methods are `fromString`, `fromBoolean`, `fromDouble` and so on. For further details about all possible |
|
|
* methods, see the [[http://circe.github.io/circe/api/io/circe/Json$.html Scala docs]]. |
|
|
* |
|
@@ -60,7 +60,7 @@ object JsonSection extends FlatSpec with Matchers with definitions.Section { |
|
|
* }}} |
|
|
* |
|
|
* |
|
|
* In addition, there are a few other methods that allow you to convert a Json object to a String. |
|
|
* In addition, there are a few other methods that allow you to convert a `Json` object to a `String`. |
|
|
* |
|
|
* {{{ |
|
|
* |
|
@@ -91,12 +91,12 @@ object JsonSection extends FlatSpec with Matchers with definitions.Section { |
|
|
* |
|
|
* }}} |
|
|
* |
|
|
* What would be the string output for our jsonFromFields value? |
|
|
* What would be the string output for our `jsonFromFields` value? |
|
|
*/ |
|
|
def jsonToString(res0: String) = |
|
|
jsonFromFields.noSpaces should be(res0) |
|
|
|
|
|
/** Let's see how we can use these methods to create custom Jsons that represents specific Json strings. |
|
|
/** Let's see how we can use these methods to create custom `Json`s that represents specific JSON strings. |
|
|
*/ |
|
|
def jsonObject(res0: Json, res1: (String, Json), res2: (String, Json), res3: Json) = { |
|
|
|
|
@@ -109,11 +109,11 @@ object JsonSection extends FlatSpec with Matchers with definitions.Section { |
|
|
|
|
|
} |
|
|
|
|
|
/** Furthemore, there are some other methods that allow you to deal with Json objects and apply transformation. We |
|
|
* can use them to modify or apply any changes to a given Json object in a simpler way, as if we we're dealing with it |
|
|
/** Furthemore, there are some other methods that allow you to deal with `Json` objects and apply transformation. We |
|
|
* can use them to modify or apply any changes to a given `Json` object in a simpler way, as if we we're dealing with it |
|
|
* manually. |
|
|
* |
|
|
* We are going to start with this Json array: |
|
|
* We are going to start with this `Json` array: |
|
|
* |
|
|
* {{{ |
|
|
* val jsonArray: Json = Json.fromValues(List( |
|
@@ -126,7 +126,7 @@ object JsonSection extends FlatSpec with Matchers with definitions.Section { |
|
|
* |
|
|
* }}} |
|
|
* |
|
|
* Finally, we have a transformJson method: |
|
|
* Finally, we have a `transformJson` method: |
|
|
* |
|
|
* {{{ |
|
|
* def transformJson(jsonArray: Json): Json = |
|
@@ -135,7 +135,7 @@ object JsonSection extends FlatSpec with Matchers with definitions.Section { |
|
|
* } |
|
|
* }}} |
|
|
* |
|
|
* So, with these in mind, what should be the result if we apply our transformJson function to our jsonArray value? |
|
|
* So, with these in mind, what should be the result if we apply our `transformJson` function to our `jsonArray` value? |
|
|
* |
|
|
*/ |
|
|
def jsonClass(res0: String) = |
|
|