jsongo

package module
v0.0.0-...-459112a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2016 License: Apache-2.0 Imports: 4 Imported by: 3

README

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 (c) 2015 Ricardo Longa.
Jsongo is licensed under the Apache License Version 2.0. See the LICENSE file for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type A

type A []interface{}

func Array

func Array() *A

func (*A) Indent

func (this *A) Indent() string

func (*A) OfString

func (this *A) OfString() (values []string, err error)

func (*A) Put

func (this *A) Put(value interface{}) *A

func (*A) Size

func (this *A) Size() int

func (*A) String

func (this *A) String() string

type O

type O map[string]interface{}

func Object

func Object() O

func (O) Get

func (this O) Get(key string) interface{}

func (O) GetArray

func (this O) GetArray(key string) (newArray *A, err error)

func (O) GetObject

func (this O) GetObject(key string) (value O, err error)

func (O) Indent

func (this O) Indent() string

func (O) Put

func (this O) Put(key string, value interface{}) O

func (O) Remove

func (this O) Remove(key string) O

func (O) String

func (this O) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL