from: Typed Data API overview (drupal.org)
// Serialize Typed Data into JSON.
$listDefinition = \Drupal::typedDataManager()->createListDataDefinition('uri');
$list = \Drupal::typedDataManager()->create($listDefinition, ['http://example.com', 'http://drupal.org']);
$serializer = \Drupal::service('serializer');
echo $serializer->serialize($list, 'json');
// ["http://example.com", "http://drupal.org"]
// Deserialize JSON into Typed Data.
$encoded = json_encode(["http://example.com", "http://drupal.org"]);
$myList = $serializer->deserialize($encoded, 'Drupal\Core\TypedData\Plugin\DataType\Uri', 'json', ['plugin_id' => 'uri']);
echo $myList->get(0)->getValue();
// 'http://example.com'