#601·jc

New parser: nftables

Author: chriscroomeCreated Sep 28, 2024Updated Sep 21, 2026
Labelsnew-parser

The nftables CLI supports JSON input and JSON output, for example:

bash
# Check JSON file
nft --check --json --file /tmp/nft.json

# List curent rules as JSON
nft --json --stateless list ruleset | jq

# Import JSON rules, first flushing existing rules
nft flush ruleset && \
nft --json --file /tmp/nft.json

However as far as I can see there is no way to take a non-JSON nftables file and render it as JSON or the reverse -- you can only read and write JSON to the kernel directly.

It would be nice to be able to do this:

bash
# Render nftables conf as JSON
cat /etc/nftables.conf | jc --nftables -p

Of course the reverse would also be nice but that would be beyond the scope of jc!

I haven't been able to find an existing way to do this, I'm not a programmer so I don't know how hard this would be to implement but this tutorial and these presentation slides have some useful background on nftables and Python / JSON support.