python icon indicating copy to clipboard operation
python copied to clipboard

FR: Pure json mode for cli --info

Open jinnatar opened this issue 4 months ago • 2 comments

At current the output of --info is a mix of command feedback (Connected to radio), protobuf style direct top level fields Owner: Meshtastic wxyz (wxyz) and json objects prefixed with a protobuf field name-ish: Nodes in mesh: { ...

Reading this format in any consistent way to extract information is painful to say the least. I'd propose the following:

  1. Output session specific feedback to STDERR (Connected to radio). This will never be useful in redirected output and is omitted completely for example in --config-export.
  2. Stick to one format that's easy to process for downstream users/admins/devs. While I understand protobuf is core to the project, it sadly lacks the proliferation of useful tooling that is available for json. If backwards compatibility is desired (although I doubt anyone has written a parser for the current format that they would want to keep) I'd say add a --json-info flag to explicitly export pure json.
  3. The json mode should output only a single object, i.e. it should wrap the distinct objects under a top level object. Example much simplified format proposed below. The goal is for example to be able to do: meshtastic --info-json | jq .Owner
{
  "Owner": "Meshtastic wxyz (wxyz)",
  "My_info": { "myNodeNum": 12345, "minAppVersion": 30200, "deviceId": "xxx==", "pioEnv": "tracker-t1000-e", "rebootCount": 0, "firmwareEdition": "VANILLA", "nodedbCount": 0 },
  "Nodes_in_mesh": {
    "!xxx": { "num": 12345 }
  },
  "Preferences": {
    "device": {
      "buzzerGpio": 25
    }
  },
  "Module_preferences": {
    "mqtt": {
      "address": "mqtt.meshtastic.org"
    }
  }
}

.. and so on, you get the point.

jinnatar avatar Aug 08 '25 17:08 jinnatar

Looking at the code this would actually be pretty easy to implement. Any objections to the concept and having it as a separate flag if go make a PR?

jinnatar avatar Aug 08 '25 17:08 jinnatar

I agree with you, I had more or less the same idea when I first saw the output, but hesitated because the output might be used withing scripting. Changes then influence other projects... But since your question nobody responded - why not just trying to change and see whats the response on the PR?

juergenRe avatar Nov 03 '25 11:11 juergenRe