Platform file sensor problem reading JSON

I’d like to show current zigbee2mqtt installed version.
So I configured a sensor like:

  - platform: file
    file_path: /opt/zigbee2mqtt/npm-shrinkwrap.json
    name: zigbee2mqtt_current_version
    value_template: "{{ value_json.version }}"

where npm-shrinkwrap.json is:

{
  "name": "zigbee2mqtt",
  "version": "1.0.1",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
    "@babel/code-frame": {
      "version": "7.0.0",
      "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz",
      "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==",
      "dev": true,
      "requires": {
        "@babel/highlight": "^7.0.0"
      }
    },
    ...
   ....// omitted
}

I’ve also set in confguration.yaml:

homeassistant:
  whitelist_external_dirs:
    - '/opt/zigbee2mqtt'

But I get always UNKNOWN.
In HA log i don’t get any error.

I also tried to use:

  - platform: file
    file_path: /home/homeassistant/.homeassistant/other/npm-shrinkwrap.json
    name: zigbee2mqtt_current_version
    value_template: "{{ value_json.version }}"

and move npm-shrinkwrap.json inside /home/homeassistant/.homeassistant/other dir to try, but always get UNKNOWN value.
What can be the problem? or how can I found the problem? I’m using latest 0.85.1

Hi, the hassio help says; The file sensor platform reads the entries from a plain-text file and shows the found value. Only the last line of the file is used. This is similar to do $ tail -n 1 sensor.txt on the command-line.

Therefore, it will only read the last line of your json file. Hope this help.

Yep.

FWIW, you can use a command_line sensor for this

- platform: command_line
  name: zigbee2mqtt_current_version
  command: "cat /opt/zigbee2mqtt/npm-shrinkwrap.json"
  value_template: >
    {{ value_json["version"] }}