goson

package module
v0.0.0-...-8eaa8c8 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: MIT Imports: 5 Imported by: 0

README

Move to https://github.com/eqto/go-json

goson

Java-like json parser for Go.

Goson created to ease json parsing and building without hasle using struct.

Install

go get -u github.com/firabliz/goson

Example

1. Json Parsing

Format JSON string and will returns the JSON Struct.

Parameters :

jsonString - it should be string format that contain JSON (check example string)

Returns :

JSON struct

Sample :

{
	"string_data": "string_value",
	"numeric_data": 1
}

How to use

//parsing json
jsObj   := goson.Parse(jsonVal)

fmt.println(jsObj.GetString(`key`))         //print: string_value

fmt.println(jsObj.GetInt(`numeric_data`))   //print: 1

2. ToString

Returns JSON text for this JSON value.

Returns :

JSON text

How to use

//parsing json
json  := goson.Parse(jsonVal)

fmt.println(json.ToString())  //print: '{"string_data": "string_value","numeric_data": 1}'
3. GetString

Returns the string value to which the specified name is mapped.

Returns :

string value

How to use

//parsing json
json   := goson.Parse(jsonVal)

fmt.println(json.GetString(`key`))         //print: string_value
4. GetJsonArray

Returns the array value to which the specified name is mapped.

Returns :

array value

How to use

//parsing json
json   := goson.Parse(jsonVal)

var arrJson []JsonObject
arrJson = json.GetJsonArray(`key`)

5. GetJsonObject

Returns the object value to which the specified name is mapped.

Returns :

object value

How to use

//parsing json
json   := goson.Parse(jsonVal)

var obj JsonObject
obj = json.GetJsonObject(`key`)


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JsonObject

type JsonObject struct {
	// contains filtered or unexported fields
}

func Parse

func Parse(data []byte) *JsonObject

func (*JsonObject) GetBoolean

func (j *JsonObject) GetBoolean(path string) *bool

func (*JsonObject) GetBooleanD

func (j *JsonObject) GetBooleanD(path string, defValue bool) bool

func (*JsonObject) GetDataMap

func (j *JsonObject) GetDataMap() map[string]interface{}

func (*JsonObject) GetFloat

func (j *JsonObject) GetFloat(path string) *float64

func (*JsonObject) GetFloatD

func (j *JsonObject) GetFloatD(path string, defValue float64) float64

func (*JsonObject) GetInt

func (j *JsonObject) GetInt(path string) *int

func (*JsonObject) GetIntD

func (j *JsonObject) GetIntD(path string, defValue int) int

func (*JsonObject) GetInterface

func (j *JsonObject) GetInterface(path string) interface{}

func (*JsonObject) GetJsonArray

func (j *JsonObject) GetJsonArray(path string) []JsonObject

func (*JsonObject) GetJsonObject

func (j *JsonObject) GetJsonObject(path string) *JsonObject

func (*JsonObject) GetString

func (j *JsonObject) GetString(path string) *string

func (*JsonObject) GetStringD

func (j *JsonObject) GetStringD(path string, defValue string) string

func (*JsonObject) Put

func (j *JsonObject) Put(path string, value interface{}) *JsonObject

func (*JsonObject) ToBytes

func (j *JsonObject) ToBytes() []byte

func (*JsonObject) ToFormattedBytes

func (j *JsonObject) ToFormattedBytes() []byte

func (*JsonObject) ToString

func (j *JsonObject) ToString() string

Jump to

Keyboard shortcuts

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