Sample Header Ad - 728x90

Use JQ to generate CSV from knife search

4 votes
3 answers
2250 views
JQ looks like a great tool, but I'm struggling with it. Here is what I am trying to do: Extract just the values from this chef knife search and generate a CSV. given this command and output: >knife search node "name:foo*" -a name -a cpu.total -a memory.total -Fj
{
  "results": 2,
  "rows": [
    {
      "foo-01": {
        "name": "foo-01",
        "cpu.total": 12,
        "memory.total": "16267368kB"
      }
    },
    {
      "foo-02": {
        "name": "foo-02",
        "cpu.total": 12,
        "memory.total": "16264296kB"
      }
    }
  ]
}
I would like to get the values extracted to CSV like this:
foo-01,12,16267368kB
foo-02,12,16264296kB
(I can deal with the quotes)
Asked by rb1980 (73 rep)
Jul 22, 2017, 02:38 AM
Last activity: Jul 11, 2021, 07:10 AM