Add json_decode filter

Created on 20 June 2023, about 1 year ago

Please add json_decode filter.
twig_tweak\src\TwigTweakExtension.php

      new TwigFilter('json_decode', [self::class, 'jsonDecode']),
...
  /**
   * Decodes a JSON string into an object or array.
   *
   * @param string $text
   *   The JSON string to decode.
   * @param bool $assoc
   *   If TRUE, will convert JSON to an associative array instead of an object.
   *
   * @return array|object
   *   The object or array equivalent of the JSON string.
   */
  public static function jsonDecode(string $text, bool $assoc = FALSE) {
    return json_decode($text, $assoc);
  }
✨ Feature request
Status

Closed: won't fix

Version

3.2

Component

Code

Created by

🇮🇱Israel Promo-IL

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Promo-IL
  • Status changed to Closed: won't fix about 1 year ago
  • 🇷🇺Russia Chi

    The use case seems very limited. And besides, this filter has nothing to do with Drupal.
    json_encode belongs to Twig core and it would be natural to put json_decode here.

    Here is there relevant pull request. Closed for the same reason (no solid use case).
    https://github.com/twigphp/Twig/pull/824

Production build 0.69.0 2024