ricardolonga / jsongo

Fluent API to make it easier to create Json objects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Jsongo

Fluent API to make it easier to create Json objects.

travis-ci codecov goreportcard

Install

go get github.com/ricardolonga/jsongo

Usage

To create this:

{  
    "name":"Ricardo Longa",
    "idade":28,
    "owner":true,
    "skills":[  
        "Golang",
        "Android"
    ]
}

Do this:

import (
    j "github.com/ricardolonga/jsongo"
)

json := j.Object().Put("name", "Ricardo Longa").
				   Put("idade", 28).
				   Put("owner", true).
				   Put("skills", j.Array().Put("Golang").
									       Put("Android"))

log.Println(json.Indent())
log.Println(json.String())
Convert object/array to indented String:
json.Indent()
Convert object/array to String:
json.String()
To remove a field of the object:
json.Remove("skills")
To get a field of the object:
json.Get("skills") // Return is interface{}.
To range over a array:
results := Array().Put("Golang").Put("Android").Put("Java")

for i, result := range results.Array() {
}
To get Array size:
array := j.Array().Put("Android").
                   Put("Golang").
                   Put("Java")
                   
array.Size() // Result is 3.

Copyright

Copyright (c) 2015 Ricardo Longa.
Jsongo is licensed under the Apache License Version 2.0. See the LICENSE file for more information.

About

Fluent API to make it easier to create Json objects.

License:Apache License 2.0


Languages

Language:Go 100.0%