jsonselect

package module
v0.0.0-...-d04eebe Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2015 License: MIT Imports: 10 Imported by: 10

README

Build Status GoDoc

go-jsonselect

A golang implementation of JSONSelect modeled off of @mwhooker's Python implementation

Supports all levels of the JSONSelect specification.

Installation

go get github.com/coddingtonbear/go-jsonselect

Usage

API documentation is available on Godoc.

JSONSelect offers many different selectors, and describing the full usage is out of the scope of this document, but should you need an overview, consult the JSONSelect documentation.

Example

Selecting all objects having a rating greater than 70 that are subordinate to a key "beers":

package main

import (
    "fmt"
    "github.com/coddingtonbear/go-jsonselect"
)

var json string = `
    {
        "beers": [
            {
                "title": "alpha",
                "rating": 50
            },
            {
                "title": "beta",
                "rating": 90
            }
        ]
    }
`

func main() {
    parser, _ := jsonselect.CreateParserFromString(json)
    results, _ := parser.GetValues(".beers object:has(.rating:expr(x>70))")
    fmt.Print(results)
    // Results [map[title: beta rating: 90]]
}

Documentation

Index

Constants

View Source
const (
	S_TYPE              tokenType = "type"
	S_IDENTIFIER        tokenType = "identifier"
	S_QUOTED_IDENTIFIER tokenType = "quoted_identifier"
	S_PCLASS            tokenType = "pclass"
	S_PCLASS_FUNC       tokenType = "pclass_func"
	S_NTH_FUNC          tokenType = "nth_func"
	S_OPER              tokenType = "operator"
	S_EMPTY             tokenType = "empty"
	S_UNK               tokenType = "unknown"
	S_FLOAT             tokenType = "float"
	S_WORD              tokenType = "word"
	S_BINOP             tokenType = "binop"
	S_BOOL              tokenType = "bool"
	S_NIL               tokenType = "null"
	S_KEYWORD           tokenType = "keyword"
	S_PVAR              tokenType = "pvar"
	S_EXPR              tokenType = "expr"
	S_NUMBER            tokenType = "number"
	S_STRING            tokenType = "string"
	S_PAREN             tokenType = "paren"
)
View Source
const (
	J_STRING  jsonType = "string"
	J_NUMBER  jsonType = "number"
	J_OBJECT  jsonType = "object"
	J_ARRAY   jsonType = "array"
	J_BOOLEAN jsonType = "boolean"
	J_NULL    jsonType = "null"

	// Not actually a type, obviously
	J_OPER jsonType = "oper"
)

Variables

This section is empty.

Functions

func EnableLogger

func EnableLogger()

Types

type Parser

type Parser struct {
	Data *simplejson.Json
	// contains filtered or unexported fields
}

func CreateParser

func CreateParser(json *simplejson.Json) (*Parser, error)

func CreateParserFromString

func CreateParserFromString(body string) (*Parser, error)

func (*Parser) GetJsonElements

func (p *Parser) GetJsonElements(selector string) ([]*simplejson.Json, error)

func (*Parser) GetValues

func (p *Parser) GetValues(selector string) ([]interface{}, error)

Jump to

Keyboard shortcuts

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