Skip to content

Support json (and pretty) output - #1610

Draft
jdhg-orbiware wants to merge 4 commits into
masterfrom
json-output
Draft

Support json (and pretty) output#1610
jdhg-orbiware wants to merge 4 commits into
masterfrom
json-output

Conversation

@jdhg-orbiware

@jdhg-orbiware jdhg-orbiware commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

This is a draft and only config get is supported as a test case scenario. Opening this draft to discuss the design decisions and get feedback. The intention here is to be more API friendly and do some exploration of this capabilities.

Many FreeBSD base tools support machine-readable output via libxo's --libxo=json (jls, netstat, ps, arp, mount, vmstat, …). Bastille today has only one JSON output at the moment: bastille list -j, which is hand-rolled in list.sh with awk and a sed pretty-printer.

Every libxo JSON document is a single top-level object shaped like:

{ ["__version": "N",] "<domain>": { "<singular-element>": [ {record}, {record}, … ] } }

The idea here for Bastille is to stay as close as possible to that format. Nevertheless, I find adding a "type" because some commands can be executed at different target-types. Like bootstrap subcommand can do releases or templates. This can be discussed if really needed or not depending if we are going to support a json output for bootstrap.

So the Bastille output is something like:

{"bastille":{"type":"<entity>","<entity>":[ {record}, ... ]}}

How to test this

For json output:
# bastille -j config TARGET get securelevel

For json (pretty) output:

# bastille -p config TARGET get securelevel

ALL is supported as target.

Both print all jails with its jid, name, and securelevel or whatever config you are testing.

If the jail is not running, the jid will simply say null

The intention here is to be more API friendly and do some exploration
of this capabilities
- Introduced `json.sh` for JSON output support.
- Updated `common.sh` to source the new JSON library.
@jdhg-orbiware

Copy link
Copy Markdown
Collaborator Author

Rebase to use the new 'lib' directory

@jdhg-orbiware jdhg-orbiware added the enhancement New feature or request label Jul 30, 2026
@tschettervictor

Copy link
Copy Markdown
Collaborator

Works for me. Good to see the new LIBDIR.

Perhaps it's better to use "${bastille_sharedir}/lib/json.sh" so it's dynamic.

@jdhg-orbiware

jdhg-orbiware commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Perhaps it's better to use "${bastille_sharedir}/lib/json.sh" so it's dynamic.

You're right. I'll also created another PR #1614 in order to update the other scripts in the common.sh file.

I'll wait @cedwards and @bmac2 comments before continuing adding other commands support. Mainly to be sure the design is good enough so I can start adding more code.

@tschettervictor

Copy link
Copy Markdown
Collaborator

I'd like to start with merging this as a first. I've got an idea about moving supported parameters or config into a lib/config file so we don't have to pollute the config.sh subcommand.

But let's wait until bmac and cedwards ok the format here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants