class Json

Same name in other branches
  1. 8.9.x core/lib/Drupal/Component/Serialization/Json.php \Drupal\Component\Serialization\Json
  2. 10 core/lib/Drupal/Component/Serialization/Json.php \Drupal\Component\Serialization\Json
  3. 11.x core/lib/Drupal/Component/Serialization/Json.php \Drupal\Component\Serialization\Json

Default serialization for JSON.

Hierarchy

Expanded class hierarchy of Json

Related topics

95 files declare their use of Json
ActiveLinkResponseFilter.php in core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
ActiveLinkResponseFilterTest.php in core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php
AssertContentTrait.php in core/tests/Drupal/KernelTests/AssertContentTrait.php
AttachedAssetsTest.php in core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php
BasicTest.php in core/modules/views/tests/src/Functional/Wizard/BasicTest.php

... See full list

109 string references to 'Json'
AcceptHeaderMatcherTest::acceptFilterProvider in core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php
Provides data for the Accept header filtering test.
AcceptHeaderMatcherTest::testNoRouteFound in core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php
Confirms that the AcceptHeaderMatcher throws an exception for no-route.
AcceptHeaderMiddleware::handle in core/modules/system/tests/modules/accept_header_routing_test/src/AcceptHeaderMiddleware.php
AdminRouteSubscriberTest::providerTestAlterRoutes in core/modules/system/tests/src/Unit/Routing/AdminRouteSubscriberTest.php
BasicTest::testViewsWizardAndListing in core/modules/views/tests/src/Functional/Wizard/BasicTest.php

... See full list

1 service uses Json
serialization.json in core/core.services.yml
Drupal\Component\Serialization\Json

File

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

Namespace

Drupal\Component\Serialization
View source
class Json implements SerializationInterface {
    
    /**
     * {@inheritdoc}
     *
     * Uses HTML-safe strings, with several characters escaped.
     */
    public static function encode($variable) {
        // Encode <, >, ', &, and ".
        return json_encode($variable, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
    }
    
    /**
     * {@inheritdoc}
     */
    public static function decode($string) {
        return json_decode($string, TRUE);
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getFileExtension() {
        return 'json';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Json::decode public static function Decodes data from the serialization format. Overrides SerializationInterface::decode
Json::encode public static function Uses HTML-safe strings, with several characters escaped. Overrides SerializationInterface::encode
Json::getFileExtension public static function Gets the file extension for this serialization format. Overrides SerializationInterface::getFileExtension

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