1

How to decode Json in Bugzilla template ?

how can I load the JSON Plugin correctly?

    [% USE JSON ( pretty => 1 ) %];

    <script type="text/javascript">

            var foo = [% foo.json %];

    </script>

    or read in JSON

    [% USE JSON %]
    [% data = JSON.json_decode(json) %]
    [% data.thing %]

it's giving me an error that plugin error - JSON: plugin not found

simbabque
  • 53,749
  • 8
  • 73
  • 136
N. Chamaa
  • 1,507
  • 3
  • 12
  • 22
  • version of Bugzilla is 5x – N. Chamaa Jun 17 '16 at 09:32
  • 1
    Do you have that plugin module installed? – simbabque Jun 17 '16 at 10:43
  • I think yes , after doing ./checksetup.pl I got a list of plugins, and the JSON XS is in Checking for JSON-XS (v2.01) ok: found v3.02 – N. Chamaa Jun 17 '16 at 12:39
  • 1
    That sounds like you have the module _JSON_ (or _JSON::XS_) installed. That's not the same as your _Template::Plugin::JSON_. See http://stackoverflow.com/a/3736710/1331451 for how to install it. The easiest way will be `cpan Template::Plugin::JSON` or `cpanm Template::Plugin::JSON` on the command line of the host that's runing the Bugzilla installation. – simbabque Jun 17 '16 at 12:42
  • Are they the same plugin JSON and JSON-XS, when I did [% USE JSON-XS %] and error with unexpected token (-) [% USE JSON-XS %] – N. Chamaa Jun 17 '16 at 12:44
  • You have to use `::` (two colons). The `-` minus is just used in distribution names. In code, you need the `::`. There is no JSON::XS plugin for Template Toolkit. In general, the _::XS_ says that it's not written in Perl, but rather it uses a C library that is connected to Perl to speed things up. – simbabque Jun 17 '16 at 12:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/114946/discussion-between-zico-and-simbabque). – N. Chamaa Jun 17 '16 at 12:50

0 Answers0