{"id":15475147,"url":"https://github.com/vsajip/jvm-cfg-lib","last_synced_at":"2026-04-16T09:39:11.508Z","repository":{"id":140255378,"uuid":"250188873","full_name":"vsajip/jvm-cfg-lib","owner":"vsajip","description":"A JVM library for working with the CFG configuration format.","archived":false,"fork":false,"pushed_at":"2025-01-10T11:00:25.000Z","size":164,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T20:37:56.115Z","etag":null,"topics":["configuration","java","java-library","kotlin","kotlin-library"],"latest_commit_sha":null,"homepage":"https://docs.red-dove.com/cfg/index.html","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vsajip.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-26T07:24:37.000Z","updated_at":"2025-01-10T11:00:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"af8e3266-9545-447c-a45f-41c938e7ef64","html_url":"https://github.com/vsajip/jvm-cfg-lib","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"c478a1212abb9e52ef4618fcd9f6f6a3a7265cf9"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Fjvm-cfg-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Fjvm-cfg-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Fjvm-cfg-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Fjvm-cfg-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vsajip","download_url":"https://codeload.github.com/vsajip/jvm-cfg-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241637646,"owners_count":19995012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","java","java-library","kotlin","kotlin-library"],"created_at":"2024-10-02T03:06:48.006Z","updated_at":"2026-04-16T09:39:11.468Z","avatar_url":"https://github.com/vsajip.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"The CFG configuration format is a text format for configuration files which is similar to, and a superset of, the JSON format. It dates from before its first announcement in [2008](https://wiki.python.org/moin/HierConfig) and has the following aims:\n\n* Allow a hierarchical configuration scheme with support for key-value mappings and lists.\n* Support cross-references between one part of the configuration and another.\n* Provide a string interpolation facility to easily build up configuration values from other configuration values.\n* Provide the ability to compose configurations (using include and merge facilities).\n* Provide the ability to access real application objects safely, where supported by the platform.\n* Be completely declarative.\n\nIt overcomes a number of drawbacks of JSON when used as a configuration format:\n\n* JSON is more verbose than necessary.\n* JSON doesn’t allow comments.\n* JSON doesn’t provide first-class support for dates and multi-line strings.\n* JSON doesn’t allow trailing commas in lists and mappings.\n* JSON doesn’t provide easy cross-referencing, interpolation, or composition.\n\nThe CFG reference implementation for the Java Virtual Machine (JVM) is written in the Kotlin programming language. The implementation assumes a JVM version of 8 or later. The Kotlin version tested with is 1.3.61 or later. The jar is usually named config-X.Y.Z.jar where X.Y.Z is the version number.\n\nInstallation\n============\nYou can install the jar from the Maven repository at https://repo1.maven.org/maven2/com/red-dove/config/ and configure Maven, Gradle etc. appropriately to use it as a dependency. The jar will be located at a path like\n\nhttps://repo1.maven.org/maven2/com/red-dove/config/X.Y.Z/config-X.Y.Z.jar\n\nWhere X.Y.Z is the version of the library.\n\nExploration\n============\nTo explore CFG functionality for the JVM, we use the Kotlin compiler in interactive mode to act as a Read-Eval-Print-Loop (REPL). Once installed, you can invoke a shell using\n```\n$ export CP=config-X.Y.Z.jar:commons-math3-3.6.1.jar:kotlin-reflect-1.3.61.jar:kotlin-stdlib-1.3.61.jar\n$ kotlinc-jvm -cp $CP\n```\nThe additional jar files are runtime dependencies of this JVM implmentation.\n\nGetting Started with CFG in Kotlin / Java\n=========================================\nA configuration is represented by an instance of the `Config` struct. The constructor for this class can be passed a filename or a stream which contains the text for the configuration. The text is read in, parsed and converted to an object that you can then query. A simple example:\n\n```\na: 'Hello, '\nb: 'world!'\nc: {\n  d: 'e'\n}\n'f.g': 'h'\nchristmas_morning: `2019-12-25 08:39:49`\nhome: `$HOME`\nfoo: `$FOO|bar`\n```\n\nLoading a configuration\n=======================\nThe configuration above can be loaded as shown below. In the REPL shell:\n\n```\n\u003e\u003e\u003e import com.reddove.config.*\n\u003e\u003e\u003e val cfg = Config(\"path/to/test0.cfg\")\n```\n\nAccess elements with keys\n=========================\nAccessing elements of the configuration with a simple key is just like using a `HashMap\u003cString, Any\u003e`:\n\n```\n\u003e\u003e\u003e cfg[\"a\"]\nres3: kotlin.Any = Hello,\n\u003e\u003e\u003e cfg[\"b\"]\nres4: kotlin.Any = world!\n```\nYou can see the types and values of the returned objects are as expected.\n\nAccess elements with paths\n==========================\nAs well as simple keys, elements  can also be accessed using `path` strings:\n```\n\u003e\u003e\u003e cfg[\"c.d\"]\nres5: kotlin.Any = e\n```\nHere, the desired value is obtained in a single step, by (under the hood) walking the path `c.d` – first getting the mapping at key `c`, and then the value at `d` in the resulting mapping.\n\nNote that you can have simple keys which look like paths:\n```\n\u003e\u003e\u003e cfg[\"f.g\"]\nres6: kotlin.Any = h\n```\nIf a key is given that exists in the configuration, it is used as such, and if it is not present in the configuration, an attempt is made to interpret it as a path. Thus, `f.g` is present and accessed via key, whereas `c.d` is not an existing key, so is interpreted as a path.\n\nAccess to date/time objects\n===========================\nYou can also get native Java `java.time.LocalDate` and `java.time.OffsetDateTime` objects from a configuration, by using an ISO date/time pattern in a `backtick-string`:\n```\n\u003e\u003e\u003e cfg[\"christmas_morning\"]\nres7: kotlin.Any = 2019-12-25T08:39:49\n\u003e\u003e\u003e cfg[\"christmas_morning\"] as java.time.LocalDateTime\nres8: java.time.LocalDateTime = 2019-12-25T08:39:49\n```\n\nAccess to other JVM objects\n===========================\nAccess to other JVM objects is also possible using the backtick-string syntax, provided that they are one of:\n\n* Environment variables\n* Public static fields of public classes\n* Public static methods without parameters of public classes\n\n```\n\u003e\u003e\u003e import java.time.LocalDate\n\u003e\u003e\u003e cfg[\"today\"] == LocalDate.now()\nres9: kotlin.Boolean = true\n\u003e\u003e\u003e import java.lang.System\n\u003e\u003e\u003e cfg[\"output\"] === System.out\nres10: kotlin.Boolean = true\n```\nAccessing the \"today\" element of the above configuration invokes the static method `java.time.LocalDate.now()` and returns its value.\n\nAccess to environment variables\n===============================\n\nTo access an environment variable, use a `backtick-string` of the form `$VARNAME`:\n```\n\u003e\u003e\u003e import java.lang.System\n\u003e\u003e\u003e cfg[\"home\"] == System.getenv(\"HOME\")\nres11: kotlin.Boolean = true\n```\nYou can specify a default value to be used if an environment variable isn’t present using the `$VARNAME|default-value` form. Whatever string follows the pipe character (including the empty string) is returned if `VARNAME` is not a variable in the environment.\n```\n\u003e\u003e\u003e cfg[\"foo\"]\nres12: kotlin.Any = bar\n```\nFor more information, see [the CFG documentation](https://docs.red-dove.com/cfg/index.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsajip%2Fjvm-cfg-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvsajip%2Fjvm-cfg-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsajip%2Fjvm-cfg-lib/lists"}