Skip to content

JQ.node transformation not applied? #16

Open
@alphatrianguli

Description

@alphatrianguli

Hi Daniel

I have the impression, my jq.node transformation is not working and I cant figure out why:

This is my JSON, that I want to transform:

[
  {
    "id": 3783740201,
    "pet_id": 299635,
    "tag_id": 427802,
    "device_id": 725206,
    "where": 2,
    "since": "2024-07-06T07:03:34Z"
  },
  {
    "id": 3783430740,
    "pet_id": 299636,
    "tag_id": 427757,
    "device_id": 725206,
    "where": 2,
    "since": "2024-07-06T05:20:00Z"
  }
]

And this is my config for the module:

{
  module: 'MMM-json',
  position: 'top_right',
  header: "Cat-Location",
  config: { // 
     url: http://192.168.0.12:8080/pets/position, // Path to your json api
     refreshInterval: 60000,
     jq: '. | map(if .where == 2 then .where = "outside" elif . == 1 then .where = "inside" else . end)',
     values: [
       {
          title: "Leia",
          query: ["$[0].where", "$[0].since"],
          prefix: ["", "(since"],
          suffix:  ["",")"]
       },
       {
          title: "Luke",
          query: ["$[1].where", "$[1].since"],
          prefix: ["", "(since"],
          suffix:  ["",")"]
       }               
     ],
     styleRules: [ // Provide custom style rules for any value
       {
          match: (value) => value == "2",
          style: "color: orange; font-weight: bold;"
       },
       {
          match: (value) => value == "1",
          style: "color: lawngreen; font-weight: bold;"
       }                    
     ],
     headerIcon: "fa-cat"                 
  }
},

When I test the jq code on https://jqplay.org/ for example, it correctly replaces "2" with the string "outside" and "1" with inside. But still, on my mirror, the values 2 and 1 are displayed - it seems the jq transformation is not applied? Can you help me out here?

Many thanks! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions