A simple YAML processor.
To parse a YAML file:
val file = File("path.to.file")
val yamlDocument = YAMLSimple.processFile(file)
The result is a YAMLDocument
, and the rootNode
property contains the root (or only) node of the tree of YAML nodes.
The tree may be navigated as if it were a JSON structure, using the jsonutil or
json-pointer libraries or others.
For example, to retrieve the description
property of the info
entry of a Swagger 2.0 YAML file:
val file = File("path.to.swagger.file")
val yamlDocument = YAMLSimple.processFile(file)
val pointer = JSONPointer("/info/description")
val description = pointer.find(yamlDocument.rootNode)
This parser does not implement the full YAML specification. The currently implemented subset includes:
- Block Mappings
- Block Sequences
- Block Scalars (literal and folded)
- Flow Scalars (plain, single quoted and double quoted)
- Flow Sequences
- Flow Mappings
- Comments
- %YAML directive
Not yet implemented:
- Anchors and Aliases
- Directives other than %YAML
- Tags
- Multiple documents in a single file
- Named floating-point pseudo-values (
.inf
,.nan
)
Also, the parser may not yet meet the specification in all respects, even for the constructs that it does handle.
The latest version of the library is 1.18, and it may be obtained from the Maven Central repository.
<dependency>
<groupId>net.pwall.yaml</groupId>
<artifactId>yaml-simple</artifactId>
<version>1.18</version>
</dependency>
implementation 'net.pwall.yaml:yaml-simple:1.18'
implementation("net.pwall.yaml:yaml-simple:1.18")
Peter Wall
2024-08-08