grass icon indicating copy to clipboard operation
grass copied to clipboard

[Feat] JSON output for g.list

Open petrasovaa opened this issue 6 months ago • 0 comments

g.list output JSON can have either a nested or flat structure, The problem with nested structure is there are multiple ways to nest it - by mapset or by type.

{
  "raster": [
    {
      "mapset": "PERMANENT",
      "name": "elevation",
      "fullname": "elevation@PERMANENT"
    }
  ],
  "vector": [
    {
      "mapset": "user1",
      "name": "roads",
      "fullname": "roads@user1"
    }
  ]
}

I am leaning towards flat format, which I think is more expected:

[
  {
    "mapset": "PERMANENT",
    "name": "elevation",
    "type": "raster",
    "fullname": "elevation@PERMANENT"
  },
  {
    "mapset": "user1",
    "name": "roads",
    "type": "vector",
    "fullname": "roads@user1"
  }
]

As for the current flags, the relevant are: -t Print data types -m Print fully-qualified map names (including mapsets) -p Pretty printing in human readable format -f Verbose listing (also list map titles)

We could have format=plain|shell|json. shell would be default to preserve current behavior.

-p flag could get deprecated and replaced by format=plain, although admittedly -p is easier.

-f I think map titles not used a whole lot, so maybe we can deprecate this flag?

Not sure about -m and -t, we could specify they apply to shell format only, currently plain format changes if parameter mapset is given.

petrasovaa avatar Jun 06 '25 13:06 petrasovaa