All Projects → m7shapan → Njson

m7shapan / Njson

Licence: apache-2.0
Unmarshal/Decode nested JSON by JSON Path

Programming Languages

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

Projects that are alternatives of or similar to Njson

Jsonui
jsonui is an interactive JSON explorer on your command line
Stars: ✭ 583 (+855.74%)
Mutual labels:  json, json-parser
Gjson
Get JSON values quickly - JSON parser for Go
Stars: ✭ 9,453 (+15396.72%)
Mutual labels:  json, json-parser
Djson
Fast Go decoder for dynamic JSON
Stars: ✭ 588 (+863.93%)
Mutual labels:  json, json-parser
Jsmnsol
A JSON parser for solidity
Stars: ✭ 56 (-8.2%)
Mutual labels:  json, json-parser
Flatjson
A fast JSON parser (and builder)
Stars: ✭ 39 (-36.07%)
Mutual labels:  json, json-parser
Json
JSON for Modern C++
Stars: ✭ 27,824 (+45513.11%)
Mutual labels:  json, json-parser
Xml Js
Converter utility between XML text and Javascript object / JSON text.
Stars: ✭ 874 (+1332.79%)
Mutual labels:  json, json-parser
Swiftyjson
The better way to deal with JSON data in Swift.
Stars: ✭ 21,042 (+34395.08%)
Mutual labels:  json, json-parser
Parson
Lightweight JSON library written in C.
Stars: ✭ 965 (+1481.97%)
Mutual labels:  json, json-parser
Jsonpath Rs
JSONPath for Rust
Stars: ✭ 31 (-49.18%)
Mutual labels:  json, json-parser
Fastjson
A fast JSON parser/generator for Java.
Stars: ✭ 23,997 (+39239.34%)
Mutual labels:  json, json-parser
Gofasion
A lightweight json parsing library for golang.
Stars: ✭ 52 (-14.75%)
Mutual labels:  json, json-parser
Coolie
Coolie(苦力) helps you to create models (& their constructors) from a JSON file.
Stars: ✭ 508 (+732.79%)
Mutual labels:  json, json-parser
Pikkr
JSON parser which picks up values directly without performing tokenization in Rust
Stars: ✭ 580 (+850.82%)
Mutual labels:  json, json-parser
Argonaut
Purely functional JSON parser and library in scala.
Stars: ✭ 501 (+721.31%)
Mutual labels:  json, json-parser
Spray Json
A lightweight, clean and simple JSON implementation in Scala
Stars: ✭ 917 (+1403.28%)
Mutual labels:  json, json-parser
Jstream
Streaming JSON parser for Go
Stars: ✭ 427 (+600%)
Mutual labels:  json, json-parser
Flatcc
FlatBuffers Compiler and Library in C for C
Stars: ✭ 434 (+611.48%)
Mutual labels:  json, json-parser
Jsondoc
JSON object for Delphi based on IUnknown and Variant
Stars: ✭ 20 (-67.21%)
Mutual labels:  json, json-parser
Univalue
High performance RAII C++ JSON library and universal value object class
Stars: ✭ 46 (-24.59%)
Mutual labels:  json, json-parser

NJson

NJSON is a Go package that Unmarshal/Decode nested JSON data depend on provided path

Installation

$ go get -u github.com/m7shapan/njson

Example

package main

import (
	"fmt"

	"github.com/m7shapan/njson"
)

func main() {
    json := `
	{
        "name": {"first": "Mohamed", "last": "Shapan"},
        "age": 26,
        "friends": [
            {"name": "Asma", "age": 26},
            {"name": "Ahmed", "age": 25},
            {"name": "Mahmoud", "age": 30}
        ]
	}`

	type User struct {
		Name    string   `njson:"name.last"`
		Age     int      `njson:"age"`
		Friends []string `njson:"friends.#.name"`
	}

	u := User{}

	err := njson.Unmarshal([]byte(json), &u)
	if err != nil {
		// do anything
	}

	fmt.Printf("%+v\n", u) // {Name:Shapan Age:26 Friends:[Asma Ahmed Mahmoud]}
}

Path Syntax

A path is a series of keys separated by a dot. A key may contain special wildcard characters '*' and '?'. To access an array value use the index as the key. To get the number of elements in an array or to access a child path, use the '#' character. The dot and wildcard characters can be escaped with ''.

{
  "name": {"first": "Tom", "last": "Anderson"},
  "age":37,
  "children": ["Sara","Alex","Jack"],
  "fav.movie": "Deer Hunter",
  "friends": [
    {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
    {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
    {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
  ]
}
"name.last"          >> "Anderson"
"age"                >> 37
"children"           >> ["Sara","Alex","Jack"]
"children.#"         >> 3
"children.1"         >> "Alex"
"child*.2"           >> "Jack"
"c?ildren.0"         >> "Sara"
"fav\.movie"         >> "Deer Hunter"
"friends.#.first"    >> ["Dale","Roger","Jane"]
"friends.1.last"     >> "Craig"

TODOs

  • [x] Add test cases
  • [ ] Improve map type Unmarshal/Decode performance
  • [ ] Improve struct type Unmarshal/Decode performance

Contact

Mohamed Shapan @m7shapan

Oh, Thanks!

By the way i want to thank Josh Baker for his package gjson

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].