Git Product home page Git Product logo

edn's Introduction

Go implementation of EDN, extensible data notation

GoDoc

go-edn is a Golang library to read and write EDN (extensible data notation), a subset of Clojure used for transferring data between applications, much like JSON or XML. EDN is also a very good language for configuration files, much like a JSON-like version of YAML.

This library is heavily influenced by the JSON library that ships with Go, and people familiar with that package should know the basics of how this library works. In fact, this should be close to a drop-in replacement for the encoding/json package if you only use basic functionality.

This implementation is fully working and (presumably) stable.

If you wonder why you should (not) use EDN, you can have a look at the why document.

Installation and Usage

The import path for the package is gopkg.in/edn.v1

To install it, run:

go get gopkg.in/edn.v1

To use it in your project, you import gopkg.in/edn.v1 and refer to it as edn like this:

import "gopkg.in/edn.v1"

//...

edn.DoStuff()

Quickstart

You can follow http://blog.golang.org/json-and-go and replace every occurence of JSON with EDN (and the JSON data with EDN data), and the text makes almost perfect sense. The only caveat is that, since EDN is more general than JSON, go-edn stores arbitrary maps on the form map[interface{}]interface{}.

go-edn also ships with keywords, symbols and tags as types.

For a longer introduction on how to use the library, see introduction.md. If you're familiar with the JSON package, then the API Documentation might be the only thing you need.

Example Usage

Say you want to describe your pet forum's users as EDN. They have the following types:

type Animal struct {
	Name string
	Type string `edn:"kind"`
}

type Person struct {
	Name      string
	Birthyear int `edn:"born"`
	Pets      []Animal
}

With go-edn, we can do as follows to read and write these types:

import "gopkg.in/edn.v1"

//...


func ReturnData() (Person, error) {
	data := `{:name "Hans",
              :born 1970,
              :pets [{:name "Cap'n Jack" :kind "Sparrow"}
                     {:name "Freddy" :kind "Cockatiel"}]}`
	var user Person
	err := edn.Unmarshal([]byte(data), &user)
	// user '==' Person{"Hans", 1970,
	//             []Animal{{"Cap'n Jack", "Sparrow"}, {"Freddy", "Cockatiel"}}}
	return user, err
}

If you want to write that user again, just Marshal it:

	bs, err := edn.Marshal(user)

Dependencies

go-edn has no external dependencies, except the default Go library. However, as it depends on math/big.Float, go-edn requires Go 1.5 or higher.

License

Copyright © 2015-2016 Jean Niklas L'orange

Distributed under the BSD 3-clause license, which is available in the file LICENSE.

edn's People

Contributors

bfontaine avatar hypirion avatar robx avatar tolitius avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.