Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuration file syntax

I'm developing software that will utilize a config file. I don't know many syntaxes or formats of config files. Here are the two I know:

(common with .conf files)

[section]
key=value
#comment

or (common with .ini)

key value
; comment

My interest is something versatile that's almost a language. Let's say

[Default]
Start = 0
End = 10
Speed = 1

[Section 3-6]
Speed = 2

This would act as an override. However this isn't any convention that I know of. Is there a common syntax that allows for this?

like image 746
Mikhail Avatar asked Sep 08 '11 14:09

Mikhail


People also ask

What is configuration syntax?

The syntax of Terraform configurations is called HashiCorp Configuration Language (HCL). It is meant to strike a balance between human readable and editable as well as being machine-friendly. For machine-friendliness, Terraform can also read JSON configurations.

What is configuration file example?

Configuration file information specifies, for example, where log files from an application are stored via the storage path, which plug-ins are allowed in a given program, and even the color scheme and dashboard widget preferences in a user interface (UI).

What is data configuration file?

In computing, configuration files (commonly known simply as config files) are files used to configure the parameters and initial settings for some computer programs. They are used for user applications, server processes and operating system settings.


1 Answers

As of 2015, xml is no longer the de facto standard. Here are options.

TOML

# This is a TOML document.

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00

[servers]

  # tabs / spaces ok but not required
  [servers.alpha]
  ip = "10.0.0.1"
  dc = "eqdc10"

YAML

%YAML 1.2
---
YAML: YAML Ain't Markup Language

Projects:
  C/C++ Libraries:
  - libyaml       # "C" Fast YAML 1.1
  - Syck          # (dated) "C" YAML 1.0
  - yaml-cpp      # C++ YAML 1.2 implementation

CSON

# Comments!!!

greatDocumentaries: [
    'earthlings.com'
    'forksoverknives.com'
]

importantFacts:
    # Multi-Line Strings! Without Quote Escaping!
    emissions: '''
        Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.
        '''

JSON5 and Human JSON - flexible json supersets

Properties File - used by java programs

like image 186
AJcodez Avatar answered Oct 02 '22 00:10

AJcodez