All Projects → panthesingh → Goson

panthesingh / Goson

Licence: mit
Handle JSON with ease in golang.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Goson

Wernicke
Redaction for structured data
Stars: ✭ 100 (-2.91%)
Mutual labels:  json
Jam Api
Parse web pages using CSS query selectors
Stars: ✭ 1,375 (+1234.95%)
Mutual labels:  json
Circe Yaml
YAML parser for circe using SnakeYAML
Stars: ✭ 102 (-0.97%)
Mutual labels:  json
Mercury
Simple Android app that sends pre-configured commands to remote servers via SSH.
Stars: ✭ 100 (-2.91%)
Mutual labels:  json
Yar
Light, concurrent RPC framework for PHP & C
Stars: ✭ 1,369 (+1229.13%)
Mutual labels:  json
Sketch Json Parser
Replaces layer values in groups with JSON data
Stars: ✭ 101 (-1.94%)
Mutual labels:  json
Parse Google Docs Json
Authenticates with Google API and parse Google Docs to JSON or Markdown
Stars: ✭ 100 (-2.91%)
Mutual labels:  json
Json2dart
Stars: ✭ 103 (+0%)
Mutual labels:  json
Iso 3166 Countries With Regional Codes
ISO 3166-1 country lists merged with their UN Geoscheme regional codes in ready-to-use JSON, XML, CSV data sets
Stars: ✭ 1,372 (+1232.04%)
Mutual labels:  json
Macholibre
Mach-O & Universal Binary Parser
Stars: ✭ 102 (-0.97%)
Mutual labels:  json
Hs Jose
Haskell JOSE and JWT library
Stars: ✭ 100 (-2.91%)
Mutual labels:  json
Eslint Plugin I18n Json
Fully extendable eslint plugin for JSON i18n translation files.
Stars: ✭ 101 (-1.94%)
Mutual labels:  json
Swagger Express Ts
Generate and serve swagger.json
Stars: ✭ 102 (-0.97%)
Mutual labels:  json
Jsonabc
Sorts JSON object alphabetically. It supports nested objects, arrays and collections. Works offline and beautifies JSON object too.
Stars: ✭ 100 (-2.91%)
Mutual labels:  json
Router
A simple, compact and fast router package to process HTTP requests
Stars: ✭ 102 (-0.97%)
Mutual labels:  json
Rki Covid Api
🦠🇩🇪📈 An API for the spread of covid-19 in Germany. Data from Robert-Koch-Institut.
Stars: ✭ 98 (-4.85%)
Mutual labels:  json
Simplejson
simplejson is a simple, fast, extensible JSON encoder/decoder for Python
Stars: ✭ 1,372 (+1232.04%)
Mutual labels:  json
Everlayout
Reusable, downloadable, up-datable iOS layouts
Stars: ✭ 103 (+0%)
Mutual labels:  json
Gitlogg
💾 🧮 🤯 Parse the 'git log' of multiple repos to 'JSON'
Stars: ✭ 102 (-0.97%)
Mutual labels:  json
Lychee
The most complete and powerful data-binding library and persistence infra for Kotlin 1.3, Android & Splitties Views DSL, JavaFX & TornadoFX, JSON, JDBC & SQLite, SharedPreferences.
Stars: ✭ 102 (-0.97%)
Mutual labels:  json

Goson

Handle JSON with ease in golang.

About

Goson was created to simplify reading JSON data within Golang. This library has been inspired by SwiftyJSON

Install

go get github.com/panthesingh/goson

Starting

Create a goson object from JSON data. Returns an error if the data is not valid JSON.

g, err := goson.Parse(data)

Data

Every Get() call will return another goson object. You can access the underlying data with a value function. The default value types are float64, int, bool, string. If the key does not exist the function will return the default zero value. To check if a key exists read the section on existence.

name := g.Get("name").String()
age := g.Get("age").Int()
weight := g.Get("weight").Float()
married := g.Get("married").Bool()

Chaining

Chaining is a nice way to quickly traverse the data and grab what you need.

g.Get("key").Get("object").Index(0).Get("item").String()

Existance

To check if a value exists use a type check on the Value() function. This returns the underlying value as an interface{}.

v, ok := g.Get("key").Value().(string)
if !ok {
  println("key does not exist")
}

Loop

Calling Len() will return len() on the underlying value. You can use the Index() function to loop through all the values.

for i := 0; i < g.Len(); i++ {
    name := g.Index(i).Get("name").String()
    age := g.Index(i).Get("age").Int()
}

Printing

A very useful feature is pretty printing the JSON structure at any value. Likewise calling String() returns the same string.

v := g.Get("child")
fmt.Println(v)

Example

package main

import (
  "github.com/panthesingh/goson"
)

func main() {

  json := `{
    "name": "Bob",
    "age": 100,
    "cars": [
      "Honda",
      "Toyota"
    ],
    "details": {
      "weight": 160.5,
      "married": false
    }
  }`

  g, _ := goson.Parse([]byte(json))
  name := g.Get("name").String()
  age := g.Get("age").Int()
  cars := g.Get("cars")
  carOne := car.Index(0).String()
  carTwo := car.Index(1).String()
  weight := g.Get("details").Get("weight").String()
  married := g.Get("details").Get("married").Bool()

}

Documentation

Documentation can be found on godoc:

https://godoc.org/github.com/panthesingh/goson

Author

Panthe Singh, http://twitter.com/panthesingh

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].