All Projects → yakaz → Yamerl

yakaz / Yamerl

Licence: other
YAML 1.2 and JSON parser in pure Erlang

Programming Languages

elixir
2628 projects
erlang
1774 projects

Projects that are alternatives of or similar to Yamerl

Eo Yaml
YAML for Java 8 and above. A user-friendly OOP library. Previously known as "Camel".
Stars: ✭ 189 (+8.62%)
Mutual labels:  yaml, parsing
python-yamlable
A thin wrapper of PyYaml to convert Python objects to YAML and back
Stars: ✭ 28 (-83.91%)
Mutual labels:  yaml, parsing
yaml.sh
Read YAML files with only Bash
Stars: ✭ 30 (-82.76%)
Mutual labels:  yaml, parsing
Neon
🍸 Encodes and decodes NEON file format.
Stars: ✭ 674 (+287.36%)
Mutual labels:  yaml, parsing
dataconf
Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.
Stars: ✭ 40 (-77.01%)
Mutual labels:  yaml, parsing
Mini Yaml
Single header YAML 1.0 C++11 serializer/deserializer.
Stars: ✭ 79 (-54.6%)
Mutual labels:  yaml, parsing
Cyberchef
The Cyber Swiss Army Knife - a web app for encryption, encoding, compression and data analysis
Stars: ✭ 13,674 (+7758.62%)
Mutual labels:  parsing
Models
WordPress plugin to create custom post types and taxonomies using JSON, YAML or PHP files
Stars: ✭ 167 (-4.02%)
Mutual labels:  yaml
K8ssandra
K8ssandra is an open-source distribution of Apache Cassandra for Kubernetes including API services and operational tooling.
Stars: ✭ 155 (-10.92%)
Mutual labels:  yaml
Abot
Cross Platform C# web crawler framework built for speed and flexibility. Please star this project! +1.
Stars: ✭ 1,961 (+1027.01%)
Mutual labels:  parsing
Cppsharp
Tools and libraries to glue C/C++ APIs to high-level languages
Stars: ✭ 2,221 (+1176.44%)
Mutual labels:  parsing
Tfk8s
A tool for converting Kubernetes YAML manifests to Terraform HCL
Stars: ✭ 167 (-4.02%)
Mutual labels:  yaml
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (-5.17%)
Mutual labels:  yaml
Pizza Sync
Pizza-Sync is a web app built on the frontend with angular, ngrx and on the backend with Nest. It let you and your friends/colleagues choose a pizza before placing a group order. Built using https://github.com/maxime1992/angular-ngrx-starter
Stars: ✭ 158 (-9.2%)
Mutual labels:  parsing
Rcc
RCC is a set of tooling that allows you to create, manage, and distribute Python-based self-contained automation packages - or 'robots' as we call them.
Stars: ✭ 168 (-3.45%)
Mutual labels:  yaml
Rats
Movie Ratings Synchronization with Python
Stars: ✭ 156 (-10.34%)
Mutual labels:  parsing
Deploy
Ansible role to deploy scripting applications like PHP, Python, Ruby, etc. in a capistrano style
Stars: ✭ 2,141 (+1130.46%)
Mutual labels:  yaml
Feedparser
feedparser gem - (universal) web feed parser and normalizer (XML w/ Atom or RSS, JSON Feed, HTML w/ Microformats e.g. h-entry/h-feed or Feed.HTML, Feed.TXT w/ YAML, JSON or INI & Markdown, etc.)
Stars: ✭ 156 (-10.34%)
Mutual labels:  yaml
Command Line Api
Command line parsing, invocation, and rendering of terminal output.
Stars: ✭ 2,418 (+1289.66%)
Mutual labels:  parsing
Python Frontmatter
Parse and manage posts with YAML (or other) frontmatter
Stars: ✭ 169 (-2.87%)
Mutual labels:  yaml

yamerl: YAML 1.2 and JSON parser in Erlang

Build Status Coverage Status Hex version

YAML is a human-friendly data serialization format. The specification for this language and many examples are available from the Official YAML web site. You may also want to check the YAML Wikipedia article.

yamerl is a pure Erlang application which is able to parse YAML 1.1 and YAML 1.2 documents, as well as JSON documents. It only depends on standard Erlang/OTP applications; no external dependency is required. It doesn't use native code either (neither port drivers nor NIFs).

yamerl can be used inside Elixir projects, like any other Erlang library. You can find an example later in this README.

yamerl is distributed under the terms of the 2-clause BSD license; see LICENSE.

Integrate to your project

yamerl uses Rebar 3 as its build system so it can be integrated to many common build systems.

Rebar

yamerl is available as a Hex.pm package. Thus you can simply list it as a package dependency in your rebar.config:

{deps, [yamerl]}.

Erlang.mk

Erlang.mk knows about yamerl. You just need to add yamerl as a dependency in your Makefile:

DEPS = yamerl

Mix

You can use yamerl in your Elixir project. yamerl is available as a Hex.pm package. Thus you can simply list its name in your mix.exs:

def project do
  [
    deps: [{:yamerl, "~> 0.8.0"}]
  ]
end

Getting started

Before using yamerl, the application must be started:

application:start(yamerl).

Now, one can use the yamerl_constr module to parse and construct a list of documents from:

  • an in-memory document (string or binary);
  • a regular file;
  • a stream.

Because a YAML input stream may contain multiple documents, yamerl_constr always returns a list of documents, even if the input stream only contains one.

Parsing an in-memory document

yamerl_constr:string("Hello World!").
% List of documents; here, only one document.
[
 % Document #1; contains a single scalar.
 "Hello World!"
]

Here, the returned value is a list of documents containing one document. This document has a scalar as its sole node.

Parsing a file

Considering the following YAML file:

# applications.yaml
- application: kernel
  version:     2.15.3
  path:        /usr/local/lib/erlang/lib/kernel-2.15.3
- application: stdlib
  version:     1.18.3
  path:        /usr/local/lib/erlang/lib/stdlib-1.18.3
- application: sasl
  version:     2.2.1
  path:        /usr/local/lib/erlang/lib/sasl-2.2.1
yamerl_constr:file("applications.yaml").
% List of documents; again, only one document here.
[
 % List of mappings.
 [
  % Mapping, represented as a proplist: each entry has the form {Key, Value}.
  [
   {"application", "kernel"},
   {"version", "2.15.3"},
   {"path", "/usr/local/lib/erlang/lib/kernel-2.15.3"}
  ], [
   {"application", "stdlib"},
   {"version", "1.18.3"},
   {"path", "/usr/local/lib/erlang/lib/stdlib-1.18.3"}
  ], [
   {"application", "sasl"},
   {"version", "2.2.1"},
   {"path", "/usr/local/lib/erlang/lib/sasl-2.2.1"}
  ]
 ]
]

Parsing a stream

The developer is responsible for reading the stream and provide the chunks to yamerl.

% Initialize a new construction state. It takes a term describing the
% source; it may be any Erlang term.
Parser0 = yamerl_constr:new({file, "<stdin>"}),

% Read chunks and feed the parser. A new parser state is returned.
{continue, Parser1} = yamerl_constr:next_chunk(Parser0, Chunk1),
% ...
{continue, Parser2} = yamerl_constr:next_chunk(Parser1, Chunk2),

% When the stream ends, tell the parser it's the last chunk.
Documents = yamerl_constr:last_chunk(Parser2, Chunk3).

Simple vs. full document structures

yamerl_constr comes with two built-in modes:

  • It can output simple documents, eg. documents based on basic Erlang structures (strings, numbers, lists, proplists). This is the default mode.
  • It can output detailed documents using records. These records carry more information such as line/column, tag URI, YAML node type, module used to construct it, etc.

If we use the following YAML document:

# system.yaml
- os: FreeBSD
  version: 9.0-RELEASE-p3
  • Simple documents:
yamerl_constr:file("system.yaml").
% List of documents.
[
    % List of mappings.
    [
     % Mapping with two entries.
     [
      {"os", "FreeBSD"},
      {"version","9.0-RELEASE-p3"}
     ]
    ]
]
  • Full documents:
yamerl_constr:file("system.yaml", [{detailed_constr, true}]).
% List of documents.
[
    % Document with a list as its root node.
    {yamerl_doc,
     {yamerl_seq, yamerl_node_seq, "tag:yaml.org,2002:seq", [{line, 2}, {column, 1}], [
      % Mapping #1.
      {yamerl_map, yamerl_node_map, "tag:yaml.org,2002:map", [{line, 2}, {column, 3}], [
       {
        % Mapping entry #1.
        {yamerl_str, yamerl_node_str, "tag:yaml.org,2002:str", [{line, 2}, {column, 3}], "os"},
        {yamerl_str, yamerl_node_str, "tag:yaml.org,2002:str", [{line, 2}, {column, 7}], "FreeBSD"}
       }, {
        % Mapping entry #2.
        {yamerl_str, yamerl_node_str, "tag:yaml.org,2002:str", [{line, 3}, {column, 3}], "version"},
        {yamerl_str, yamerl_node_str, "tag:yaml.org,2002:str", [{line, 3}, {column, 12}], "9.0-RELEASE-p3"}
       }
      ]}
     ],
     1}
    }
]

Use yamerl in an Elixir project

Here is a complete example:

  1. You first need to add yamerl to the dependencies list in mix.exs:
# mix.exs, created with `mix new myapp` and updated to have `yamerl` as
# a dependency.
defmodule Myapp.Mixfile do
 use Mix.Project

 def project do
   [app: :myapp,
    version: "0.1.0",
    elixir: "~> 1.3",
    build_embedded: Mix.env == :prod,
    start_permanent: Mix.env == :prod,
    deps: deps()]
 end

 # Configuration for the OTP application
 #
 # Type "mix help compile.app" for more information
 def application do
   [applications: [:logger]]
 end

 # Dependencies can be Hex packages:
 #
 #   {:mydep, "~> 0.3.0"}
 #
 # Or git/path repositories:
 #
 #   {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
 #
 # Type "mix help deps" for more examples and options
 defp deps do
   [
     {:yamerl, "~> 0.4.0"}
   ]
 end
end
  1. Start the yamerl application and use the constructor, either in simple or detailed mode:
# lib/myapp.ex
defmodule Myapp do
 def simple(filename) do
   # The yamerl application must be started before any use of it.
   Application.start(:yamerl)

   :yamerl_constr.file(filename)
 end

 def detailed(filename) do
   # The yamerl application must be started before any use of it.
   Application.start(:yamerl)

   :yamerl_constr.file(filename, [:detailed_constr])
 end
end

Now let's use the Myapp module to parse the same YAML example file as above:

# system.yaml
- os: FreeBSD
  version: 9.0-RELEASE-p3
  • Parsing in simple mode:
Myapp.simple("system.yaml")
# List of documents.
[
    # List of mappings.
    [
     # Mapping with two entries.
     [
      {'os', 'FreeBSD'},
      {'version', '9.0-RELEASE-p3'}
     ]
    ]
]
  • Parsing in detailed mode:
Myapp.detailed("system.yaml")
# List of documents.
[
    # Document with a list as its root node.
    yamerl_doc:
    {:yamerl_seq, :yamerl_node_seq, 'tag:yaml.org,2002:seq', [line: 2, column: 1],
     [
      # Mapping #1.
      {:yamerl_map, :yamerl_node_map, 'tag:yaml.org,2002:map', [line: 2, column: 3],
       [
        # Mapping entry #1.
        {
         {:yamerl_str, :yamerl_node_str, 'tag:yaml.org,2002:str', [line: 2, column: 3], 'os'},
         {:yamerl_str, :yamerl_node_str, 'tag:yaml.org,2002:str', [line: 2, column: 7], 'FreeBSD'}
        },
        # Mapping entry #2.
        {
         {:yamerl_str, :yamerl_node_str, 'tag:yaml.org,2002:str', [line: 3, column: 3], 'version'},
         {:yamerl_str, :yamerl_node_str, 'tag:yaml.org,2002:str', [line: 3, column: 12], '9.0-RELEASE-p3'}
        }
       ]
      }
     ],
     1
    }
]

Complete documentation

See https://hexdocs.pm/yamerl/ for a complete user guide and reference manual.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].