Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnlcox/toml4j
A Java parser for TOML
https://github.com/johnlcox/toml4j
Last synced: about 2 months ago
JSON representation
A Java parser for TOML
- Host: GitHub
- URL: https://github.com/johnlcox/toml4j
- Owner: johnlcox
- License: other
- Created: 2013-02-25T03:37:25.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2020-10-13T01:32:40.000Z (about 4 years ago)
- Last Synced: 2024-04-16T11:19:57.968Z (9 months ago)
- Language: Java
- Homepage:
- Size: 61.5 KB
- Stars: 14
- Watchers: 4
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# toml4j
[![Build Status](https://travis-ci.org/johnlcox/toml4j.png?branch=master)](https://travis-ci.org/johnlcox/toml4j)
A Java parser for [toml](https://github.com/mojombo/toml) files, currently supporting version 0.4.0 of the spec. The parse result is a navigable tree of nodes.
## Usage
Use the `TomlParser` to parse a TOML file or string. The parsed result can be consumed in two ways.
### Key/Value Based
If the TOML structure is already known, the key/value approach is a simple abstraction of the TOML tree with easy key based accessors.
```java
InputStream tomlInpuStream = new FileInputStream("config.toml");
Toml toml = Toml.from(new FileInputStream("config.toml"));String serviceName = toml.getString("name");
String dbServer = toml.getString("database.server");
boolean isDbEnabled = toml.getBoolean("database.enabled");String serverIp = toml.getString("server.alpha.ip");
```### Tree Based
With the tree based approach it is possible to easily traverse a TOML structure that is not known a priori.
```java
InputStream tomlInpuStream = new FileInputStream("config.toml");
TomlNode tomlNode = new TomlParser().parse(tomlInputStream);String serviceName = tomlNode.get("name").stringValue();
TomlNode databaseNode = tomlNode.get("database");
String dbServer = serverNode.get("server").stringValue();
boolean isDbEnabled = serverNode.get("enabled").booleanValue();TomlNode serverNode = tomlNode.get("servers").get("alpha");
String serverIp = serverNode.get("ip").stringValue();
```## License
Copyright 2013 John Leacox
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.