function Json::encode

Same name in other branches
  1. 9 core/lib/Drupal/Component/Serialization/Json.php \Drupal\Component\Serialization\Json::encode()
  2. 8.9.x core/lib/Drupal/Component/Serialization/Json.php \Drupal\Component\Serialization\Json::encode()
  3. 11.x core/lib/Drupal/Component/Serialization/Json.php \Drupal\Component\Serialization\Json::encode()

Uses HTML-safe strings, with several characters escaped.

Overrides SerializationInterface::encode

78 calls to Json::encode()
ActiveLinkResponseFilter::setLinkActiveClass in core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
Sets the "is-active" class and aria-current attribute on relevant links.
ActiveLinkResponseFilterTest::providerTestSetLinkActiveClass in core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php
Provides test data for testSetLinkActiveClass().
AjaxTestController::httpMethods in core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php
Provides an Ajax link used with different HTTP methods.
BigPipeTest::testBigPipe in core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
Tests BigPipe-delivered HTML responses when JavaScript is enabled.
BlockLibraryController::listBlocks in core/modules/block/src/Controller/BlockLibraryController.php
Shows a list of blocks that can be added to a theme's layout.

... See full list

File

core/lib/Drupal/Component/Serialization/Json.php, line 17

Class

Json
Default serialization for JSON.

Namespace

Drupal\Component\Serialization

Code

public static function encode($variable) {
    // Encode <, >, ', &, and ".
    return json_encode($variable, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.