For example, if some library doesn't implement parsing one command 's output, like cluster nodes, users need to parse themselves.

Avoid reinventing the wheel of parsing output text

If redis-cli support an option like --json-out so that all commands are wrapped to a JSON, libraries don't need to implement the parsing themself.

What they need is to define model object, and decode to it, return to the user.

Comment From: atlas-comstock

@antirez Any ideas?Thanks

Comment From: bjsmiley

Looks like this can be closed

➜ redis-cli --help | grep json
  --json             Output in JSON format (default RESP3, use -2 if you want to use with RESP2).
  --quoted-json      Same as --json, but produce ASCII-safe quoted strings, not Unicode.

Comment From: ginolegigot

Is it really working ? i tried these options on redis 7.4, with redis-cli cluster nodes, it did not produce a json reply

Comment From: sundb

@ginolegigot can you give the details about how you using.

Comment From: ginolegigot

sure thanks for your reply:

redis-cli --tls --cacert /path/to/ca -c -h NodeFQDN --user xxxx --pass xxxx --json cluster nodes

also tried --json right after redis-cli or --quoted-json

Comment From: sundb

@ginolegigot https://redis.io/docs/latest/commands/cluster-nodes/

RESP2/RESP3 Reply
[Bulk string reply](https://redis.io/docs/latest/develop/reference/protocol-spec#bulk-strings): the serialized cluster configuration.

the reply of CLUSTER NODES is string, not array.

Comment From: ginolegigot

Yes and would it be possible to jsonify this string output ? would be much easier to deal with, for example using the output in ansible scripts. maybe should i make a proper issue for it ? The global underlying question/need here being, is it possible to jsonify every redis-cli output for better handling of out puts ?

Comment From: sundb

Yes and would it be possible to jsonify this string output ?

but how can we jsonify a string? the root layer of json must be [] or {}.

would be much easier to deal with, for example using the output in ansible scripts.

i recommend to reprocess the output of a string in your script.

Comment From: ginolegigot

Thanks for your reply. i guess redis-cli is calling some redis api to get information, maybe you could implement in redis cli, a jsonifying of cluster nodes api for example (or any others api which returns a string instead of an array), like if we pass --json it gives something from:

e73319f5dffzfzefzzf93adfb24cf11db1149656 xxxxxxxxxxxxx:6379@16379 slave 24dd68e643ed8xxdgdegeghguurrxhrhre79ee2c 0 1724212339738 3 connected
422f80317abezfzfbjra97c8d59bfc8e1563f896 xxxxxxxxxxxxx:6379@16379 slave d661711dzdzgrgeyeeteteytruiturhk468329a1 0 1724931311000 2 connected
d661711f5fzfzjhhezg107dc114d27ce468329a1 xxxxxxxxxxxxx:6379@16379 master - 0 1724961269000 2 connected 5461-10922

to:

[
{
  "node_id": "e73319f5dffzfzefzzf93adfb24cf11db1149656",
  "node_ip": "xxx.xxx.xxx.xxx,
  "cluster_role": "slave"
},
{
  "node_id": "422f80317abezfzfbjra97c8d59bfc8e1563f89",
  "node_ip": "xxx.xxx.xxx.xxx,
  "cluster_role": "slave"
},
{
  "node_id": "d661711f5fzfzjhhezg107dc114d27ce468329a1",
  "node_ip": "xxx.xxx.xxx.xxx,
  "cluster_role": "master"
}
]

Like elasticsearch (among others), an example of a response from listing the nodes in elasticsearch:

  {
    "ip": "xx.xx.xx.xxx",
    "heap.percent": "36",
    "ram.percent": "75",
    "cpu": "0",
    "load_1m": "0.05",
    "load_5m": "0.07",
    "load_15m": "0.08",
    "node.role": "cdffsfsfstw",
    "master": "-",
    "name": "yolo1"
  },
  {
    "ip": "xxx.xxx.xxx.xxx",
    "heap.percent": "47",
    "ram.percent": "72",
    "cpu": "0",
    "load_1m": "0.01",
    "load_5m": "0.05",
    "load_15m": "0.04",
    "node.role": "cdfdfdffstw",
    "master": "-",
    "name": "yolo2"
  }

In elasticsearch when you set up a cluster with ansible it's really handy to get the features of nodes and rearrange the cluster if needed etc... I dont know your code archiecture and how much it would be time consuming to add this feature but to administrate redis cluster it would be ready handy

Comment From: sundb

@ginolegigot why not using cluster shards? i think it's what you want. If we want cluster nodes to support output json, we have to change its reply format to array or map instead of string.