Zum Ende der Metadaten springen
Zum Anfang der Metadaten

LoxBerry 1.4

This shell tool is included in LoxBerry starting with LoxBerry V1.4. If you use that function, set this minimum version in your plugin.cfg.

LoxBerry ships with the tool jq, that can read and edit json files, as well as find values. The tools website is here, and more useful examples are listed here.

Simple examples

Sample json for the following examples

{
  "NOTIFICATION": [
    "MAIL_SYSTEM_ERROR",
    "MAIL_SYSTEM_INFOS"
  ],
  "SMTP": {
    "ACTIVATE_MAIL": "1",
    "CRYPT": 1,
    "EMAIL": "christian@mydomain.com",
    "PORT": "587",
    "SMTPPASS": "Eins, zwei, Polizei",
    "SMTPSERVER": "smtp.mailserver.com"
  }
}

Take note that NOTIFICATION is an array, and SMTP is an object with elements.

Return the value of a key

$ jq '.SMTP.EMAIL' test.json
"christian@mydomain.com"

$ jq -r '.SMTP.EMAIL' test.json
christian@mydomain.com

$ jq '.NOTIFICATION' test.json
[
  "MAIL_SYSTEM_ERROR",
  "MAIL_SYSTEM_INFOS"
]

Test if an array element exists

$ jq '.NOTIFICATION | contains(["MAIL_SYSTEM_INFOS"])' test.json
true
$ jq '.NOTIFICATION | contains(["nonsense"])' test.json
false


Change a value

This is setting "ACTIVATE_MAIL": to "0".

# jq '.SMTP.ACTIVATE_MAIL = "0"' test.json > testnew.json

Take special care that you cannot directly replace the original file, as the jq parser operates line by line. Therefore you need to create a new file, and then move it over the old one.

  • Keine Stichwörter