JSON input / output for CLI utilities

Andrew Walker awalker at ixsystems.com
Thu Jun 3 13:28:03 UTC 2021


Here is some sample output for "net conf list":
```
root at debian:/CODE/samba# bin/default/source3/utils/net --json conf list | jq
{
  "version": {
    "major": 1,
    "minor": 0
  },
  "sections": [
    {
      "service": "global",
      "is_share": false,
      "parameters": []
    },
    {
      "service": "share",
      "is_share": true,
      "parameters": [
        {
          "name": "path",
          "raw": "/tank",
          "parsed": "/tank"
        },
        {
          "name": "guest ok",
          "raw": "no",
          "parsed": false
        },
        {
          "name": "read only",
          "raw": "false",
          "parsed": false
        },
        {
          "name": "vfs objects",
          "raw": "streams_xattr zfsacl",
          "parsed": "streams_xattr zfsacl"
        }
      ]
    }
  ]
}
```
Basically, root JSON object has two keys, "version", and "sections". Each
section is composed of a service name, whether it's a share, and an array
of parameters.
Each parameter has "name", "raw", and "parsed" keys. The name is the
parameter name, the raw output is the string returned from libsmbconf, and
parsed is an attempt to put the value into a correct-ish JSON type.

Is there anything we should add here?

I took the liberty of making it so that "net conf setparm" can take an
array of parameters:
```
root at debian:/CODE/samba# bin/default/source3/utils/net --json conf setparm
'{"service": "share", "parameters": [{"name": "read only", "parsed":
false}, {"name": "vfs objects", "raw": "streams_xattr zfsacl"}]}'
```
Parameters can be set either by parsed or raw values.

"net conf delparm" takes an array of JSON parameters:
```
 bin/default/source3/utils/net --json conf delparm '{"service": "share",
"parameters": [{"name": "vfs objects"}]}'
```

"net conf addshare" can set all required parameters on share creation:
```
root at debian:/CODE/samba# bin/default/source3/utils/net --json conf addshare
'{"service": "share", "parameters": [{"name": "read only", "parsed":
false}, {"name": "vfs objects", "raw": "streams_xattr zfsacl"}, {"name":
"path", "raw": "/tank"}]}'
```

Any feedback regarding how this is structured is welcome.


More information about the samba-technical mailing list