What is this type of file AND is there a parser?

type: confs
targets:
 - /opt
excludes:
 - ".whicotew.phsusr"
cron_min: "5"
cron_hour: "00"
uploads:
 - rsync

I’m searching for its parser like jq for JSON.

Asked By: palmasd1

||

It looks like a YAML file – but without any context, it’s difficult to give any more details.

There is a Python YAML parser in the Universe repositories – the package name is yamllint.

Answered By: Artur Meinild

As noted in this answer, your file appears to be YAML.

If you are already familiar with jq you may find the jq wrapper kislyuk /
yq
(installable via pip) useful. To simply convert your file to JSON for example:

$ yq '.' yourfile
{
  "type": "confs",
  "targets": [
    "/opt"
  ],
  "excludes": [
    ".whicotew.phsusr"
  ],
  "cron_min": "5",
  "cron_hour": "00",
  "uploads": [
    "rsync"
  ]
}

or to extract a value

$ yq -r '.targets[0]' yourfile
/opt

or to add to the targets array and output the result as YAML

$ yq -y '.targets += ["/media"]' yourfile
type: confs
targets:
  - /opt
  - /media
excludes:
  - .whicotew.phsusr
cron_min: '5'
cron_hour: '00'
uploads:
  - rsync
Answered By: steeldriver
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.