diff --git a/client/contact/src/Tests/ContactItemHandlerTest.php b/client/contact/src/Tests/ContactItemHandlerTest.php
index 3f3a4bf..008b513 100644
--- a/client/contact/src/Tests/ContactItemHandlerTest.php
+++ b/client/contact/src/Tests/ContactItemHandlerTest.php
@@ -7,6 +7,7 @@
 namespace Drupal\collect_client_contact\Tests;
 
 use Drupal\collect_client\CollectItem;
+use Drupal\Component\Serialization\Json;
 use Drupal\contact\Entity\Message;
 use Drupal\simpletest\KernelTestBase;
 use Drupal\user\Entity\User;
@@ -108,7 +109,7 @@ class ContactItemHandlerTest extends KernelTestBase {
       'account' => $user,
       'message' => $message,
     ));
-    $data = json_decode($item->data, TRUE);
+    $data = Json::decode($item->data);
 
     $this->assertTrue($item instanceof CollectItem, 'Handle returned a collect item.');
     $this->assertEqual('https://drupal.org/project/collect_client/contact', $item->schema_uri, 'Schema set cot contact schema uri.');
diff --git a/client/src/Plugin/QueueWorker/CollectClientQueueWorker.php b/client/src/Plugin/QueueWorker/CollectClientQueueWorker.php
index 37d84be..b4ca008 100644
--- a/client/src/Plugin/QueueWorker/CollectClientQueueWorker.php
+++ b/client/src/Plugin/QueueWorker/CollectClientQueueWorker.php
@@ -8,6 +8,7 @@ namespace Drupal\collect_client\Plugin\QueueWorker;
 
 use Drupal\collect_client\CollectItem;
 use Drupal\Component\Plugin\PluginManagerInterface;
+use Drupal\Component\Serialization\Json;
 use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\Config\Config;
 use Drupal\Core\Logger\LoggerChannelInterface;
@@ -286,7 +287,7 @@ class CollectClientQueueWorker extends QueueWorkerBase implements ContainerFacto
       }
 
       // Decode received data.
-      $json = json_decode($body->getContents(), TRUE);
+      $json = Json::decode($body->getContents());
 
       if ($property == 'uuid') {
         return isset($json['data'][$property]) ? $json['data'][$property] : FALSE;
@@ -313,7 +314,7 @@ class CollectClientQueueWorker extends QueueWorkerBase implements ContainerFacto
    *   The array containing results of CollectItem serialization.
    */
   protected function getTransferObjects(CollectItem $collect_item) {
-    $data = json_decode($collect_item->data, TRUE);
+    $data = Json::decode($collect_item->data);
 
     if (json_last_error()) {
       return [];
@@ -325,7 +326,7 @@ class CollectClientQueueWorker extends QueueWorkerBase implements ContainerFacto
       $values_container_uri = $collect_item->uri;
       $collect_item->uri = $collect_item->schema_uri;
       $collect_item->schema_uri = 'http://schema.md-systems.ch/collect/0.0.1/collectjson-definition/global/fields';
-      $collect_item->data = json_encode(['fields' => $data['fields']]);
+      $collect_item->data = Json::encode(['fields' => $data['fields']]);
       $options['body'] = $this->serializer->serialize($collect_item, 'json');
       $transfer_objects[] = $options;
 
@@ -333,7 +334,7 @@ class CollectClientQueueWorker extends QueueWorkerBase implements ContainerFacto
       unset($data['fields']);
       $collect_item->schema_uri = $collect_item->uri;
       $collect_item->uri = $values_container_uri;
-      $collect_item->data = json_encode($data);
+      $collect_item->data = Json::encode($data);
       $options['body'] = $this->serializer->serialize($collect_item, 'json');
       $transfer_objects[] = $options;
     }
diff --git a/client/src/Plugin/collect_client/EntityItemHandler.php b/client/src/Plugin/collect_client/EntityItemHandler.php
index b9c978d..5c6b051 100644
--- a/client/src/Plugin/collect_client/EntityItemHandler.php
+++ b/client/src/Plugin/collect_client/EntityItemHandler.php
@@ -8,6 +8,7 @@ namespace Drupal\collect_client\Plugin\collect_client;
 
 use Drupal\collect_client\CollectItem;
 use Drupal\Component\Plugin\PluginBase;
+use Drupal\Component\Serialization\Json;
 use Drupal\Core\TypedData\ListDataDefinition;
 
 /**
@@ -76,7 +77,7 @@ class EntityItemHandler extends PluginBase implements ItemHandlerInterface {
     // Expand field definitions with URI definitions for entity reference fields.
     $fields = collect_common_add_uri_definitions(\Drupal::entityManager(), $serializer, $entity->getFieldDefinitions(), $fields);
 
-    $result->data = json_encode([
+    $result->data = Json::encode([
       'values' => $values,
       'fields' => $fields,
       'operation' => $item['operation'],
diff --git a/client/src/Tests/CollectClientWebTest.php b/client/src/Tests/CollectClientWebTest.php
index d7399ed..d81acb4 100644
--- a/client/src/Tests/CollectClientWebTest.php
+++ b/client/src/Tests/CollectClientWebTest.php
@@ -7,6 +7,7 @@
 namespace Drupal\collect_client\Tests;
 
 use Drupal\collect\Entity\Container;
+use Drupal\Component\Serialization\Json;
 use Drupal\Component\Utility\SafeMarkup;
 use Drupal\simpletest\WebTestBase;
 
@@ -157,7 +158,7 @@ class CollectClientWebTest extends WebTestBase {
     // Assert that uuid property is added into captured data.
     $image_container = Container::load($this->getLatestId() - 4);
     $user_container = Container::load($this->getLatestId() - 2);
-    $data = json_decode($user_container->getData(), TRUE);
+    $data = Json::decode($user_container->getData());
     $this->assertEqual($data['values']['_links']['field_user_picture'][0]['uuid'], $image_container->uuid());
 
     // Edit article details to test continuous entity update.
@@ -197,7 +198,7 @@ class CollectClientWebTest extends WebTestBase {
     \Drupal::service('cron')->run();
 
     $user_client_container = Container::load($this->getLatestId());
-    $user_client_values = json_decode($user_client_container->getData(), TRUE)['values'];
+    $user_client_values = Json::decode($user_client_container->getData())['values'];
 
     // Capture a user through collect.
     $this->drupalPostForm('admin/content/collect/capture', [
@@ -210,7 +211,7 @@ class CollectClientWebTest extends WebTestBase {
     ], t('Capture'));
 
     $user_server_container = Container::load($this->getLatestId());
-    $user_server_values = json_decode($user_server_container->getData(), TRUE)['values'];
+    $user_server_values = Json::decode($user_server_container->getData())['values'];
 
     // Assert that both containers are the same.
     $this->assertEqual($user_server_values, $user_client_values);
diff --git a/src/CaptureEntity.php b/src/CaptureEntity.php
index 8a40a5c..ec37f0a 100644
--- a/src/CaptureEntity.php
+++ b/src/CaptureEntity.php
@@ -10,6 +10,7 @@ namespace Drupal\collect;
 use Drupal\collect\Entity\Container;
 use Drupal\collect\Model\ModelManagerInterface;
 use Drupal\collect\Plugin\collect\Model\FieldDefinition;
+use Drupal\Component\Serialization\Json;
 use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Entity\EntityManagerInterface;
 use Symfony\Component\HttpFoundation\RequestStack;
@@ -140,7 +141,7 @@ class CaptureEntity {
       'origin_uri' => $origin_uri,
       'schema_uri' => $schema_uri,
       'type' => static::MIMETYPE,
-      'data' => json_encode(['values' => $values, 'operation' => $operation]),
+      'data' => Json::encode(['values' => $values, 'operation' => $operation]),
     ]);
 
     // Create the fields container.
@@ -152,7 +153,7 @@ class CaptureEntity {
       'origin_uri' => $schema_uri,
       'schema_uri' => FieldDefinition::URI,
       'type' => static::MIMETYPE,
-      'data' => json_encode(['fields' => $fields]),
+      'data' => Json::encode(['fields' => $fields]),
     ]);
 
     return [
diff --git a/src/Controller/CollectContainerController.php b/src/Controller/CollectContainerController.php
index 6351d8e..8b52283 100644
--- a/src/Controller/CollectContainerController.php
+++ b/src/Controller/CollectContainerController.php
@@ -8,6 +8,7 @@ namespace Drupal\collect\Controller;
 
 use Drupal\collect\CaptureEntity;
 use Drupal\collect\CollectContainerInterface;
+use Drupal\collect\Serialization\Json;
 use Drupal\Component\Utility\SafeMarkup;
 use Drupal\Component\Utility\Xss;
 use Drupal\Core\Controller\ControllerBase;
@@ -190,13 +191,13 @@ class CollectContainerController extends ControllerBase {
 
     if ($type == 'application/json') {
       // Pretty-print JSON.
-      $data = json_decode($data);
+      $data = Json::decode($data);
       if (json_last_error()) {
         // If decoding fails, output raw.
         $string = SafeMarkup::checkPlain($data);
         return array('#markup' => $this->t('Decoding error: %message', ['%message' => json_last_error_msg()]) . " <pre>$string</pre>");
       }
-      $string = json_encode($data, JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK|JSON_UNESCAPED_SLASHES);
+      $string = Json::encodePretty($data);
       $string = SafeMarkup::checkPlain($string);
       return array('#markup' => "<pre>$string</pre>");
     }
diff --git a/src/Controller/CreateEntityController.php b/src/Controller/CreateEntityController.php
index aac86ca..55817db 100644
--- a/src/Controller/CreateEntityController.php
+++ b/src/Controller/CreateEntityController.php
@@ -9,6 +9,7 @@ namespace Drupal\collect\Controller;
 use Drupal\collect\CollectContainerInterface;
 use Drupal\collect\Plugin\collect\Model\CollectJson;
 use Drupal\collect\Model\ModelManagerInterface;
+use Drupal\Component\Serialization\Json;
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Controller\ControllerBase;
 use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -68,7 +69,7 @@ class CreateEntityController extends ControllerBase {
     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     $entity = entity_create($entity_type, $values);
 
-    $data = json_decode($collect_container->getData(), TRUE);
+    $data = Json::decode($collect_container->getData());
     $entity_values = $data['values'];
 
     // Move the entity reference fields into top level.
diff --git a/src/Controller/FieldDefinitionDiffController.php b/src/Controller/FieldDefinitionDiffController.php
index 68f3b1b..0b62d36 100644
--- a/src/Controller/FieldDefinitionDiffController.php
+++ b/src/Controller/FieldDefinitionDiffController.php
@@ -13,6 +13,7 @@ use Drupal\collect\Plugin\collect\Model\FieldDefinition;
 use Drupal\collect\Model\ModelInterface;
 use Drupal\Component\Diff\Diff;
 use Drupal\Component\Diff\DiffFormatter;
+use Drupal\collect\Serialization\Json;
 use Drupal\Component\Utility\SafeMarkup;
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Controller\ControllerBase;
@@ -73,8 +74,8 @@ class FieldDefinitionDiffController extends ControllerBase {
     $build = ['#title' => $this->t('Compare with current Field Definition data')];
 
     $field_definition_container_id = FieldDefinition::findDefinitionContainer($collect_model);
-    $stored_field_definition = json_decode(Container::load($field_definition_container_id)->getData(), TRUE)['fields'];
-    $stored_field_definition_json = json_encode(FieldDefinition::removeEntityReferenceFields($stored_field_definition), JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES);
+    $stored_field_definition = Json::decode(Container::load($field_definition_container_id)->getData())['fields'];
+    $stored_field_definition_json = Json::encodePretty(FieldDefinition::removeEntityReferenceFields($stored_field_definition));
     $current_field_definition_json = $this->getCurrentFieldDefinitions($collect_model);
 
     $field_diff_rows = $this->getRows($stored_field_definition_json, $current_field_definition_json);
@@ -131,7 +132,7 @@ class FieldDefinitionDiffController extends ControllerBase {
     foreach ($field_definitions as $field_name => $definition) {
       $fields[$field_name] = $this->serializer->normalize($field_definitions[$field_name], 'json');
     }
-    return json_encode($fields, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES);
+    return Json::encodePretty($fields);
   }
 
   /**
diff --git a/src/Controller/GenerateWebPageController.php b/src/Controller/GenerateWebPageController.php
index 916a7e9..d67d3bb 100644
--- a/src/Controller/GenerateWebPageController.php
+++ b/src/Controller/GenerateWebPageController.php
@@ -9,6 +9,7 @@ namespace Drupal\collect\Controller;
 use Drupal\collect\CollectContainerInterface;
 use Drupal\collect\Plugin\collect\Model\FetchUrl;
 use Drupal\collect\Model\ModelManagerInterface;
+use Drupal\Component\Serialization\Json;
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Controller\ControllerBase;
 use Symfony\Component\HttpFoundation\Response;
@@ -49,7 +50,7 @@ class GenerateWebPageController extends ControllerBase {
    * Generates a web page from raw html/json data.
    */
   public function generatePage(CollectContainerInterface $collect_container) {
-    $data = json_decode($collect_container->getData(), TRUE);
+    $data = Json::decode($collect_container->getData());
     $content = $data['body'];
     $content_type = 'text/html';
     if (!empty($data['response-headers']['Content-Type'])) {
diff --git a/src/FetchWebResource.php b/src/FetchWebResource.php
index ea18e20..52efab7 100644
--- a/src/FetchWebResource.php
+++ b/src/FetchWebResource.php
@@ -9,6 +9,7 @@ namespace Drupal\collect;
 
 use Drupal\collect\Entity\Container;
 use Drupal\collect\Model\ModelManagerInterface;
+use Drupal\Component\Serialization\Json;
 use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Entity\EntityManagerInterface;
 use GuzzleHttp\ClientInterface;
@@ -147,7 +148,7 @@ class FetchWebResource {
 
     $json_encoded_data = FALSE;
     if (Unicode::validateUtf8($data['body'])) {
-      $json_encoded_data = json_encode($data);
+      $json_encoded_data = Json::encode($data);
     }
 
     if (!$json_encoded_data) {
diff --git a/src/Plugin/collect/Model/CollectJson.php b/src/Plugin/collect/Model/CollectJson.php
index ef10a41..c822bbd 100644
--- a/src/Plugin/collect/Model/CollectJson.php
+++ b/src/Plugin/collect/Model/CollectJson.php
@@ -11,6 +11,8 @@ use Drupal\collect\Model\DynamicModelTypedDataInterface;
 use Drupal\collect\Model\PropertyDefinition;
 use Drupal\collect\TypedData\CollectDataInterface;
 use Drupal\collect\TypedData\TypedDataProvider;
+use Drupal\collect\Plugin\collect\Model\Json;
+use Drupal\Component\Serialization\Json as SerializationJson;
 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
 use Psr\Log\LoggerInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -206,7 +208,7 @@ class CollectJson extends Json implements DynamicModelTypedDataInterface, Contai
   public function generatePropertyDefinitions(CollectContainerInterface $collect_container) {
 
     // Decode JSON. Log and return if decoding fails.
-    $values_data = json_decode($collect_container->getData(), TRUE);
+    $values_data = SerializationJson::decode($collect_container->getData());
     if (!isset($values_data) || !isset($values_data['values'])) {
       $this->logger->info('Collect JSON data is missing values.');
       return array();
diff --git a/src/Plugin/collect/Model/Json.php b/src/Plugin/collect/Model/Json.php
index 8a6aa41..7e976d5 100644
--- a/src/Plugin/collect/Model/Json.php
+++ b/src/Plugin/collect/Model/Json.php
@@ -8,6 +8,7 @@ namespace Drupal\collect\Plugin\collect\Model;
 
 use Drupal\collect\CollectContainerInterface;
 use Drupal\collect\Model\ModelPluginBase;
+use Drupal\Component\Serialization\Json as SerializationJson;
 
 /**
  * Provides support for JSON data, using a subset of JsonPath for queries.
@@ -26,7 +27,7 @@ class Json extends ModelPluginBase {
    * {@inheritdoc}
    */
   public function parse(CollectContainerInterface $collect_container) {
-    return json_decode($collect_container->getData(), TRUE);
+    return SerializationJson::decode($collect_container->getData());
   }
 
 }
diff --git a/src/Serialization/Json.php b/src/Serialization/Json.php
new file mode 100644
index 0000000..d0e4657
--- /dev/null
+++ b/src/Serialization/Json.php
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Component\Serialization\Json.
+ */
+
+namespace Drupal\collect\Serialization;
+
+/**
+ * Pretty serialization for JSON.
+ */
+class Json extends \Drupal\Component\Serialization\Json {
+
+  /**
+   * Pretty json encoding.
+   *
+   * Uses HTML-safe strings, with several characters escaped.
+   */
+  public static function encodePretty($variable) {
+    // Encode <, >, ', &, and ".
+    return json_encode($variable, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES);
+  }
+
+}
diff --git a/src/Tests/CollectJsonModelTest.php b/src/Tests/CollectJsonModelTest.php
index 347ffa1..00c51cd 100644
--- a/src/Tests/CollectJsonModelTest.php
+++ b/src/Tests/CollectJsonModelTest.php
@@ -10,6 +10,7 @@ use Drupal\collect\Entity\Container;
 use Drupal\collect\Entity\Model;
 use Drupal\collect\Plugin\collect\Model\FieldDefinition;
 use Drupal\collect\Model\PropertyDefinition;
+use \Drupal\Component\Serialization\Json;
 use Drupal\Core\TypedData\DataDefinition;
 use Drupal\field\Entity\FieldConfig;
 use Drupal\field\Entity\FieldStorageConfig;
@@ -144,7 +145,7 @@ class CollectJsonModelTest extends KernelTestBase {
     /** @var \Drupal\collect\Entity\Container $container */
     $container = Container::create([
       'schema_uri' => 'schema:test',
-      'data' => json_encode([
+      'data' => Json::encode([
         'fields' => [
           // Basic string.
           'dog' => [
diff --git a/src/Tests/CollectWebTest.php b/src/Tests/CollectWebTest.php
index 6e5da56..bf03c42 100644
--- a/src/Tests/CollectWebTest.php
+++ b/src/Tests/CollectWebTest.php
@@ -8,6 +8,7 @@ namespace Drupal\collect\Tests;
 
 use Drupal\collect\Entity\Container;
 use Drupal\collect\Entity\Model;
+use Drupal\Component\Serialization\Json;
 use Drupal\Core\Datetime\DrupalDateTime;
 use Drupal\simpletest\WebTestBase;
 
@@ -276,7 +277,7 @@ class CollectWebTest extends WebTestBase {
       '@plugin' => t('Collect Fetch URL'),
     ]));
     $this->clickLink(t('Show content in a new window'));
-    $data = json_decode(Container::load($first_url_container_id)->getData(), TRUE);
+    $data = Json::decode(Container::load($first_url_container_id)->getData());
     $this->assertEqual($data['request-headers']['Accept'][0], '');
     $body = $data['body'];
     $this->assertEqual($body, $this->getRawContent());
@@ -300,14 +301,14 @@ class CollectWebTest extends WebTestBase {
     $this->fetchWebResource(200);
     $this->clickLink(t('here'));
     \Drupal::entityManager()->getStorage('collect_container')->resetCache();
-    $data = json_decode(Container::load($first_url_container_id)->getData(), TRUE);
+    $data = Json::decode(Container::load($first_url_container_id)->getData());
     $this->assertEqual($data['request-headers']['Accept'][0], 'text/html');
 
     // Test Fetch URL form with application/json header and assert JSON format.
     $this->fetchWebResource(200, 'application/json');
     $this->clickLink(t('here'));
     \Drupal::entityManager()->getStorage('collect_container')->resetCache();
-    $data = json_decode(Container::load($first_url_container_id)->getData(), TRUE);
+    $data = Json::decode(Container::load($first_url_container_id)->getData());
     $this->assertEqual($data['body'], '{"headers": {"status_code": 200}}');
     $this->assertEqual($data['request-headers']['Accept'][0], 'application/json');
 
@@ -320,14 +321,14 @@ class CollectWebTest extends WebTestBase {
     ), t('Get page'));
     $this->clickLink(t('here'));
     \Drupal::entityManager()->getStorage('collect_container')->resetCache();
-    $data = json_decode(Container::load($first_url_container_id)->getData(), TRUE);
+    $data = Json::decode(Container::load($first_url_container_id)->getData());
     $this->assertEqual($data['request-headers']['Accept'][0], 'application/json');
 
     // Test Fetch URL form with application/json header and assert JSON format.
     $this->fetchWebResource(200, 'application/json');
     $this->clickLink(t('here'));
     \Drupal::entityManager()->getStorage('collect_container')->resetCache();
-    $data = json_decode(Container::load($first_url_container_id)->getData(), TRUE);
+    $data = Json::decode(Container::load($first_url_container_id)->getData());
     $this->clickLink(t('Show content in a new window'));
 
     // Tests body, headers of the generated web resource.
@@ -357,7 +358,7 @@ class CollectWebTest extends WebTestBase {
     $this->clickLink(t('here'));
     $this->assertText(t('Web resource content has been converted from ISO-8859-1 to UTF-8 charset.'));
     \Drupal::entityManager()->getStorage('collect_container')->resetCache();
-    $data = json_decode(Container::load($this->getLatestId())->getData(), TRUE);
+    $data = Json::decode(Container::load($this->getLatestId())->getData());
     $this->clickLink(t('Show content in a new window'));
     $this->assertEqual($data['body'], $this->getRawContent());
 
diff --git a/src/Tests/FetchUrlModelTest.php b/src/Tests/FetchUrlModelTest.php
index 8483d46..9a77ddd 100644
--- a/src/Tests/FetchUrlModelTest.php
+++ b/src/Tests/FetchUrlModelTest.php
@@ -9,6 +9,7 @@ namespace Drupal\collect\Tests;
 use Drupal\collect\Entity\Container;
 use Drupal\collect\Entity\Model;
 use Drupal\collect\Model\PropertyDefinition;
+use Drupal\Component\Serialization\Json;
 use Drupal\Core\TypedData\DataDefinition;
 use Drupal\simpletest\KernelTestBase;
 
@@ -31,7 +32,7 @@ class FetchUrlModelTest extends KernelTestBase {
    */
   public function testProperties() {
     $container = Container::create([
-      'data' => json_encode([
+      'data' => Json::encode([
         'request-headers' => ['Accept' => ['text/html']],
         'response-headers' => ['Content-Type' => ['text/html']],
         'body' => '<html><body>Body text</body></html>',
diff --git a/src/Tests/FieldDefinitionModelTest.php b/src/Tests/FieldDefinitionModelTest.php
index bcce026..9180fc1 100644
--- a/src/Tests/FieldDefinitionModelTest.php
+++ b/src/Tests/FieldDefinitionModelTest.php
@@ -8,6 +8,7 @@ namespace Drupal\collect\Tests;
 
 use Drupal\collect\Entity\Container;
 use Drupal\collect\Plugin\collect\Model\FieldDefinition;
+use Drupal\Component\Serialization\Json;
 use Drupal\Core\Field\FieldDefinitionInterface;
 use Drupal\Core\TypedData\DataDefinitionInterface;
 use Drupal\simpletest\KernelTestBase;
@@ -48,7 +49,7 @@ class FieldDefinitionModelTest extends KernelTestBase {
    */
   public function testProperties() {
     $field_container = Container::create([
-      'data' => json_encode([
+      'data' => Json::encode([
         'fields' => [
           'nid' => [
             'type' => 'field_item',
@@ -93,7 +94,7 @@ class FieldDefinitionModelTest extends KernelTestBase {
     $this->assertEqual('The Node ID', $nid_definition->getDescription());
 
     // Accessing property with no value should return empty.
-    $field_container->setData(json_encode(['fields' => []]));
+    $field_container->setData(Json::encode(['fields' => []]));
     $field_container->save();
     $data = $typed_data_provider->getTypedData($field_container);
     $fields = $data->get('fields')->getValue();
diff --git a/src/Tests/ModelTest.php b/src/Tests/ModelTest.php
index a7c13a6..f91c1b5 100644
--- a/src/Tests/ModelTest.php
+++ b/src/Tests/ModelTest.php
@@ -9,6 +9,7 @@ namespace Drupal\collect\Tests;
 use Drupal\collect\Entity\Container;
 use Drupal\collect\Entity\Model;
 use Drupal\collect\Model\PropertyDefinition;
+use Drupal\Component\Serialization\Json;
 use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\Core\TypedData\ComplexDataDefinitionInterface;
@@ -203,7 +204,7 @@ class ModelTest extends KernelTestBase {
     // Create some complex JSON data.
     $container = Container::create([
       'schema_uri' => 'schema:json',
-      'data' => json_encode([
+      'data' => Json::encode([
         'simple' => 'foo',
         'complex' => [
           'one' => 'eins',
diff --git a/tests/modules/collect_test/src/Plugin/collect/Model/TestModelPlugin.php b/tests/modules/collect_test/src/Plugin/collect/Model/TestModelPlugin.php
index a7d7b64..1ee13e1 100644
--- a/tests/modules/collect_test/src/Plugin/collect/Model/TestModelPlugin.php
+++ b/tests/modules/collect_test/src/Plugin/collect/Model/TestModelPlugin.php
@@ -10,6 +10,7 @@ use Drupal\collect\CollectContainerInterface;
 use Drupal\collect\Model\PropertyDefinition;
 use Drupal\collect\Model\ModelPluginBase;
 use Drupal\collect\TypedData\CollectDataInterface;
+use Drupal\Component\Serialization\Json;
 use Drupal\Core\TypedData\DataDefinition;
 
 /**
@@ -41,7 +42,7 @@ class TestModelPlugin extends ModelPluginBase {
    * {@inheritdoc}
    */
   public function parse(CollectContainerInterface $collect_container) {
-    return json_decode($collect_container->getData(), TRUE);
+    return Json::decode($collect_container->getData());
   }
 
   /**
