• Stars
    star
    112
  • Rank 303,120 (Top 7 %)
  • Language
    Julia
  • License
    Other
  • Created over 11 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Parse yer YAMLs

YAML

CI codecov

YAML is a flexible data serialization format that is designed to be easily read and written by human beings.

This library parses YAML documents into native Julia types and dumps them back into YAML documents.

Synopsis

For most purposes there is one important function: YAML.load, which takes a string and parses it the first YAML document it finds.

To parse a file use YAML.load_file, and to parse every document in a file use YAML.load_all or YAML.load_all_file.

Given a YAML document like the following

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

bill-to:  &id001
    street: |
            123 Tornado Alley
            Suite 16
    city:   East Centerville
    state:  KS

ship-to:  *id001

specialDelivery:  >
    Follow the Yellow Brick
    Road to the Emerald City.
    Pay no attention to the
    man behind the curtain.

It can be loaded with

import YAML
data = YAML.load_file("test.yml")
println(data)

Which will show you something like this.

{"date"=>Aug 6, 2012 12:00:00 AM PDT,"ship-to"=>{"street"=>"123 Tornado Alley\nSuite 16\n","state"=>"KS","city"=>"East Centerville"},"customer"=>{"given"=>"Dorothy","family"=>"Gale"},"specialDelivery"=>"Follow the Yellow Brick\nRoad to the Emerald City.\nPay no attention to the\nman behind the curtain.\n","items"=>{{"price"=>1.47,"descrip"=>"Water Bucket (Filled)","part_no"=>"A4786","quantity"=>4}  …  {"price"=>100.27,"size"=>8,"descrip"=>"High Heeled \"Ruby\" Slippers","part_no"=>"E1628","quantity"=>1}},"bill-to"=>{"street"=>"123 Tornado Alley\nSuite 16\n","state"=>"KS","city"=>"East Centerville"},"receipt"=>"Oz-Ware Purchase Invoice"}

Note that ints and floats are recognized, as well as timestamps which are parsed into CalendarTime objects. Also, anchors and references work as expected, without making a copy.

Dictionaries are parsed into instances of Dict{Any,Any} by default. You can, however, specify a custom type in which to parse all dictionaries.

# using Symbol keys
data = YAML.load_file("test.yml"; dicttype=Dict{Symbol,Any})

# maintaining the order from the YAML file
using OrderedCollections
data = YAML.load_file("test.yml"; dicttype=OrderedDict{String,Any})

# specifying a default value
using DataStructures
data = YAML.load_file("test.yml"; dicttype=()->DefaultDict{String,Any}(Missing))

Writing to YAML

Similar to reading files, you can emit Julia objects to YAML files by calling write_file, or to a string object by calling write.

For example, you can reproduce the above file from the variable data

import YAML
YAML.write_file("test-output.yml", data)

which gives you (omitting the precise format but maintaining the content)

receipt: "Oz-Ware Purchase Invoice"
items:
  - part_no: "A4786"
    price: 1.47
    descrip: "Water Bucket (Filled)"
    quantity: 4
  - part_no: "E1628"
    price: 100.27
    size: 8
    descrip: "High Heeled "Ruby" Slippers"
    quantity: 1
customer:
  given: "Dorothy"
  family: "Gale"
ship-to:
  city: "East Centerville"
  street: |
      123 Tornado Alley
      Suite 16

  state: "KS"
bill-to:
  city: "East Centerville"
  street: |
      123 Tornado Alley
      Suite 16

  state: "KS"
specialDelivery: |
    Follow the Yellow Brick Road to the Emerald City. Pay no attention to the man behind the curtain.

date: 2012-08-06

Not yet implemented

  • When writing YAML files, you cannot use additional constructors like you can when reading.
  • Parsing sexigesimal numbers.
  • Fractions of seconds in timestamps.
  • Specific time-zone offsets in timestamps.
  • Application specific tags.

More Repositories

1

DataFrames.jl

In-memory tabular data in Julia
Julia
1,680
star
2

JuliaDB.jl

Parallel analytical database in pure Julia
Julia
762
star
3

DataFramesMeta.jl

Metaprogramming tools for DataFrames
Julia
472
star
4

CSV.jl

Utility library for working with CSV and other delimited files in the Julia programming language
Julia
448
star
5

Tables.jl

An interface for tables in Julia
Julia
288
star
6

TypedTables.jl

Simple, fast, column-based storage for data analysis in Julia
Julia
144
star
7

SplitApplyCombine.jl

Split-apply-combine strategies for Julia
Julia
143
star
8

CategoricalArrays.jl

Arrays for working with categorical data (both nominal and ordinal)
Julia
121
star
9

IndexedTables.jl

Flexible tables with ordered indices
Julia
117
star
10

Parsers.jl

fast parsing machinery for basic types in Julia
Julia
111
star
11

Feather.jl

Read and write feather files in pure Julia
Julia
108
star
12

InvertedIndices.jl

A simple index type that allows for inverted selections
Julia
80
star
13

StructTypes.jl

Abstract definitions and convenience methods for describing, processing, and constructing Julia objects
Julia
75
star
14

Missings.jl

Missing value support for Julia
Julia
66
star
15

JSONTables.jl

JSON3.jl + Tables.jl
Julia
64
star
16

RData.jl

Read R data files from Julia
Julia
61
star
17

DataStreams.jl

[DEPRECATED in favor of https://github.com/JuliaData/Tables.jl] A fast, generic framework for transferring table-like data structures in Julia
Julia
61
star
18

Strapping.jl

Tools for mapping between Julia structs and 2D tabular data.
Julia
56
star
19

PooledArrays.jl

A pooled representation for arrays with few unique elements
Julia
47
star
20

TableOperations.jl

Common table operations on Tables.jl interface implementations
Julia
45
star
21

FlatBuffers.jl

A pure Julia implementation of google flatbuffers
Julia
40
star
22

JuliaDBMeta.jl

Metaprogramming tools for JuliaDB
Julia
33
star
23

DataAPI.jl

A data-focused namespace for packages to share functions
Julia
33
star
24

NamedTuples.jl

[DEPRECATED] NamedTuples.jl
Julia
30
star
25

DataTables.jl

(DEPRECATED) A rewrite of DataFrames.jl based on Nullable
Julia
29
star
26

SentinelArrays.jl

Array types that can use sentinel values of the element type for special values
Julia
22
star
27

WeakRefStrings.jl

a minimal String type for Julia that allows for efficient string representation and transfer
Julia
22
star
28

MemPool.jl

High-performance parallel and distributed datastore for Julia
Julia
21
star
29

TableMetadataTools.jl

Tools for working with metadata of Tables.jl tables in Julia.
Julia
18
star
30

DelimitedFiles.jl

A package for reading and writing files with delimited values (Originally a Julia stdlib)
Julia
15
star
31

Avro.jl

Pure Julia implementation for reading/writing data in the Avro format
Julia
15
star
32

DBFTables.jl

Read and write DBF (dBase) tabular data in Julia
Julia
10
star
33

JuliaDB_Benchmarks

Reproducible benchmarks for JuliaDB
HTML
8
star
34

DataStreamsIntegrationTests.jl

[DEPRECATED]
Julia
2
star
35

juliadb.org

Website for JuliaDB
HTML
2
star