How to load (import) config from JSON?

What would be the easiest way to load config from JSON?
Current API supports exporting config as JSON, but to load it the vyos config format is needed.
There seems to be no docs about the vyos config format spec or a way to generate it from JSON.
Any suggestions would be appreciated.
Thanks

You can look at /config/config.boot, in fact it is the same as the path used during configuration

If you need to load in vyos, you can use load

The load command does not support JSON format.
My question was how to use JSON directly or what is the mapping function from JSON to vyos config format as there is no spec for it.
Intuitively there seem to be some flattening if the object value contains only one object, but the format is not documented anywhere:

this config

a b {
  c d
  e f         
}

makes this json

a: {
  b: {
      c: d,
      e: f,
  }
}

There is a HTTPS API that can be configured but it does not appear to be strictly JSON format. It’s also possible to script various commands via SSH if you’re feeding the JSON in to something like Ansible.

You can only export config as JSON with that api, so it doesn’t answer my question.

In configuration mode, use the following command to export the configuration of vyos

save <file>

The configuration must be commit first

Yup, I agree. I don’t think it’s currently possible. I had a dig around the VyOS Phabricator and there’s an in-progress Task about exporting to JSON and this one about saving version data as JSON but I don’t see any about importing. You could submit a feature request on Phabricator about this.

EDIT: I know they are working hard on completely redoing the configuration backend called VyConf. https://github.com/vyos/vyconf so this may simply be a limitation of the current backend.

I think it’s JSON-like. Based on the description on T1773, it makes me believe https://github.com/vyos/libvyosconfig is needed to properly parse it. I have not tried this myself, however.

last commit was 9 months ago. I wonder whether the config overhaul is going to come via some other route?

I find the Project Updates in the blog really informative about the state of the project. Although, I am having memory recall issues as of late and can’t remember the specific posts about the backend migration status but I do remember reading them. Sorry that’s not more help.

There’s also the VyConf Phabricator.

Hello @helushune, did you try the following command from configure mode?

vyos@RTR1:~$ configure 
[edit]
vyos@RTR1# run show configuration | json

It successfully works my VyOS test router with rolling

Hi @Dmitry, Thank you, I appreciate the insight. That looks like it works great.

I’ve created a feature request on Phabricator as suggested.