title: extract json with javascript preprocessing Zabbix
body: <p>i'm trying to extrapolate a json if a string is contained. My json is this:</p>
  <pre><code>[
     {
        &quot;name&quot;:&quot;PE02S-PK00400_2002&quot;,
        &quot;ip&quot;:&quot;&quot;,
        &quot;pk&quot;:0.4,
        &quot;roadCode&quot;:&quot;A32&quot;,
        &quot;roadName&quot;:&quot;A32&quot;,
        &quot;roadDescription&quot;:&quot;A32 TORINO-BARDONECCHIA&quot;,
        &quot;directionName&quot;:&quot;A32_DIR_A&quot;,
        &quot;directionDescription&quot;:&quot;BARDONECCHIA&quot;,
        &quot;sectionName&quot;:&quot;A32_DIR_A_SEZ1&quot;,
        &quot;sectionDescription&quot;:&quot;RIVOLI - SUSA&quot;,
        &quot;laneName&quot;:null,
        &quot;laneDescription&quot;:null,
        &quot;tunnelName&quot;:&quot;A32_GALLERY_LA_PEROSA&quot;,
        &quot;tunnelDescription&quot;:&quot;LA PEROSA&quot;,
        &quot;idTecnico&quot;:&quot;2002&quot;
     },
     {
        &quot;name&quot;:&quot;PE04S-PK00500_2004&quot;,
        &quot;ip&quot;:&quot;&quot;,
        &quot;pk&quot;:0.5,
        &quot;roadCode&quot;:&quot;A32&quot;,
        &quot;roadName&quot;:&quot;A32&quot;,
        &quot;roadDescription&quot;:&quot;A32 TORINO-BARDONECCHIA&quot;,
        &quot;directionName&quot;:&quot;A32_DIR_A&quot;,
        &quot;directionDescription&quot;:&quot;BARDONECCHIA&quot;,
        &quot;sectionName&quot;:&quot;A32_DIR_A_SEZ1&quot;,
        &quot;sectionDescription&quot;:&quot;RIVOLI - SUSA&quot;,
        &quot;laneName&quot;:null,
        &quot;laneDescription&quot;:null,
        &quot;tunnelName&quot;:&quot;A32_GALLERY_LA_PEROSA&quot;,
        &quot;tunnelDescription&quot;:&quot;LA PEROSA&quot;,
        &quot;idTecnico&quot;:&quot;2004&quot;
     },
     {
        &quot;name&quot;:&quot;PE06S-PK00750_2006&quot;,
        &quot;ip&quot;:&quot;&quot;,
        &quot;pk&quot;:0.75,
        &quot;roadCode&quot;:&quot;A32&quot;,
        &quot;roadName&quot;:&quot;A32&quot;,
        &quot;roadDescription&quot;:&quot;A32 TORINO-BARDONECCHIA&quot;,
        &quot;directionName&quot;:&quot;A32_DIR_A&quot;,
        &quot;directionDescription&quot;:&quot;BARDONECCHIA&quot;,
        &quot;sectionName&quot;:&quot;A32_DIR_A_SEZ1&quot;,
        &quot;sectionDescription&quot;:&quot;RIVOLI - SUSA&quot;,
        &quot;laneName&quot;:null,
        &quot;laneDescription&quot;:null,
        &quot;tunnelName&quot;:&quot;A32_GALLERY_LA_PEROSA&quot;,
        &quot;tunnelDescription&quot;:&quot;LA PEROSA&quot;,
        &quot;idTecnico&quot;:&quot;2006&quot;
     }
  ]
  </code></pre>
  <p>The javascript script is this:</p>
  <pre><code>function (value) {
      var res = ''
      var json = JSON.parse(value)
  
      for (i = 0; i &lt; json.length; i++) {
  
          if (json[i].name =~ &quot;{HOST.NAME}&quot;) {
  
              res = JSON.stringify(json[i])
  
              return res
          }
  
      }
  
  }
  </code></pre>
  <p>{HOST.NAME} is SOS-PE02S-PK00400</p>
  <p>Everything works, except the field (name) is -1.</p>
  <p>Here is the result:</p>
  <pre><code>{
     &quot;name&quot;:-1,
     &quot;ip&quot;:&quot;&quot;,
     &quot;pk&quot;:0.4,
     &quot;roadCode&quot;:&quot;A32&quot;,
     &quot;roadName&quot;:&quot;A32&quot;,
     &quot;roadDescription&quot;:&quot;A32 TORINO-BARDONECCHIA&quot;,
     &quot;directionName&quot;:&quot;A32_DIR_A&quot;,
     &quot;directionDescription&quot;:&quot;BARDONECCHIA&quot;,
     &quot;sectionName&quot;:&quot;A32_DIR_A_SEZ1&quot;,
     &quot;sectionDescription&quot;:&quot;RIVOLI - SUSA&quot;,
     &quot;laneName&quot;:null,
     &quot;laneDescription&quot;:null,
     &quot;tunnelName&quot;:&quot;A32_GALLERY_LA_PEROSA&quot;,
     &quot;tunnelDescription&quot;:&quot;LA PEROSA&quot;,
     &quot;idTecnico&quot;:&quot;2002&quot;
  }
  </code></pre>
  <p>Here is the result I would expect:</p>
  <pre><code>{
     &quot;name&quot;:&quot;PE02S-PK00400_2002&quot;,
     &quot;ip&quot;:&quot;&quot;,
     &quot;pk&quot;:0.4,
     &quot;roadCode&quot;:&quot;A32&quot;,
     &quot;roadName&quot;:&quot;A32&quot;,
     &quot;roadDescription&quot;:&quot;A32 TORINO-BARDONECCHIA&quot;,
     &quot;directionName&quot;:&quot;A32_DIR_A&quot;,
     &quot;directionDescription&quot;:&quot;BARDONECCHIA&quot;,
     &quot;sectionName&quot;:&quot;A32_DIR_A_SEZ1&quot;,
     &quot;sectionDescription&quot;:&quot;RIVOLI - SUSA&quot;,
     &quot;laneName&quot;:null,
     &quot;laneDescription&quot;:null,
     &quot;tunnelName&quot;:&quot;A32_GALLERY_LA_PEROSA&quot;,
     &quot;tunnelDescription&quot;:&quot;LA PEROSA&quot;,
     &quot;idTecnico&quot;:&quot;2002&quot;
  }
  </code></pre>
  <p>I don't understand where is wrong. If you can help me I am grateful.
  Thank you very much.</p>