JSON Encode and Decode | Drupal 8

JSON Encode and Decode

Submitted by editor on Wed, 05/18/2016 - 23:02

How to encode and decode JSON array/string in drupal 8 way like drupal_json_encode and drupal_json_decode in drupal 7 ?

Example :

use Drupal\Component\Serialization\Json;
$json = Json::encode($data);
$data = Json::decode($json);

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.