Drupal 8 node serialization to JSON I am trying to use \Drupal\node\Entity\Node::load($nid) to store a node object in a variable and pass the variable into drupal 8's serialization component or even symphony's serialization methods. All my efforts have resulted in a JSON object that is only encoding the first property of the node which is {"in_preview":null}.

For example the following callback returns {"in_preview":null}

public function page(){

  $nrm = new \Drupal\Component\Serialization\Json;
  $node = Node::load(2);
  $json = $nrm -&gt; encode($node, 'json');

  return $json;

}


What class/method would accomplish serialization of $node in the above code?
You should use the serializer service if you want to serialize a Drupal data type (Typed Data API) so that normalization is run properly. This requires enabling the serialization module as pointed out by Alari Truuts, which defines the serializer service.

The serialize method is a little confusing as to what the $context parameter means. For Drupal Typed Data, it requires the plugin id of the data type (EntityAdapter in this case).

$serializer = \Drupal::service('serializer');
$node = Node::load(2);
$data = $serializer-&gt;serialize($node, 'json', ['plugin_id' =&gt; 'entity']);