Giter Club home page Giter Club logo

json_spanner's Introduction

JSON SPANNER

JSON Spanner is a Go package that provides a fast and simple way to filter or transform a json document. You can filter or transform json using SQL-like statements.

Getting Started

Installing

To start using JSON Spanner, install Go and run go get:

$ go get -u github.com/fuhongbo/json_spanner

This will retrieve the library.

Filter a json document

Use SQL-like statements to filter JSON, return true if conditions are met, and return false if not.

package main

import (
	"fmt"
	"github.com/fuhongbo/json_spanner"
)

func main() {
	eng, _ := NewFilter("test.a.b=1 and (b=2 or c=4)")
	result := eng.Valid(`{"test":{"a":{"b":1}},"b":3,"c":4}`)
	fmt.Println(result)
}

This will print:

true

Transform a json document

Use SQL-like statements to transform JSON.

package main

import "fmt"

func main() {
	eng, err := NewQuery("select test.a as x.t, 6.8 as x.d,b as x.b,c where test.a=1 and (b=2 or c=4)")
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	match, jsonStr, err := eng.Transform(`{"test":{"a":1},"b":3,"c":4}`)
    
	if !match{
		fmt.Println("the json document do not match the condition")
		return
    } 
	
	if err!=nil{
		fmt.Println(err.Error())
		return
    }
	fmt.Println(jsonStr)
}

This will print:

{
    "c": 4,
    "x": {
        "b": 3,
        "d": 6.8,
        "t": 1
    }
}

Currently supported conditional expressions

Expressions Remark
=
<>
>
>=
<
<=
AND
OR
=~ This special use to MQTT topic match

json_spanner's People

Contributors

endeavorecho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.