Skip to content

sanketmeghani/jezyaml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jezyaml

Java EasyYaml - jezyaml is a light wrapper for reading YAML in Java. It uses snakeyaml to load YAML from a String or a File. jezyaml provides easy APIs to get values defined in YAML.

Usage

Instantiating EasyYaml

You can instantiate EasyYaml either using a YAML string or a YAML file. To instantiate using a string:

String yamlString = "a: 'string'\nb: 2\nc:\n  - aaa\n  - bbb\nd: false";

EasyYaml easyYaml = EasyYaml.fromString(yamlString);

To instantiate using a .yml file:

String yamlFile = "sample.yml";

EasyYaml easyYaml = EasyYaml.fromFile("sample.yml");

Accessing Values

Sample YAML

receipt:     Oz-Ware Purchase Invoice
date:        2012-08-06
customer:
    given:   Dorothy
    family:  Gale

items:
    - part_no:   A4786
      descrip:   Water Bucket (Filled)
      price:     1.47
      quantity:  4

    - part_no:   E1628
      descrip:   High Heeled "Ruby" Slippers
      size:      8
      price:     100.27
      quantity:  1

To retrieve String value:

String value = easyYaml.getString("receipt");

To retrieve nested values, pass a dotted key:

String customerName = easyYaml.getString("customer.given");

To retrieve a `List':

List<Object> values = easyYaml.getList("items");

Similar accessor methods avaialble for other data types as well. You can also pass a default value to be returned in case of given key is not found in YAML.

String defaultValue = "Not Available";

//Returns "Not Available"
String contactNo = easyYaml.getString("customer.contactNo", defaultValue);

About

A light weight Java wrapper over snakeyaml to conveniently read YAML

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages