• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 13 years ago
  • Updated over 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CSS-like selectors for JSON (Ruby implementation).

JSONSelect Build Status

CSS-like selectors for JSON.

More info about the JSON:select format

Installation

From your terminal:

gem install json_select

In your Gemfile:

gem 'json_select'

Usage

require 'json_select'

json = { # This would normally be loaded with something like yajl-ruby
  "name" => {
    "first" => "Lloyd",
    "last" => "Hilaiel"
  },
  "favoriteColor" => "yellow",
  "languagesSpoken" => [
    {
      "language" => "Bulgarian",
      "level" => "advanced"
    },
    {
      "language" => "English",
      "level" => "native"
    },
    {
      "language" => "Spanish",
      "level" => "beginner"
    }
  ],
  "seatingPreference" => [ "window", "aisle" ],
  "drinkPreference" => [ "beer", "whiskey", "wine" ],
  "weight" => 172
}

JSONSelect('string:first-child').test(json)    # => true
JSONSelect('string:first-child').match(json)   # => "window"
JSONSelect('string:first-child').matches(json) # => ["window", "beer"]

Language support

โœ“ โ€” Level 1 โ€” *
Any node

โœ“ โ€” Level 1 โ€” T
A node of type T, where T is one string, number, object, array, boolean, or null

โœ“ โ€” Level 1 โ€” T.key
A node of type T which is the child of an object and is the value its parents key property

โœ“ โ€” Level 1 โ€” T."complex key"
Same as previous, but with property name specified as a JSON string

โœ“ โ€” Level 1 โ€” T:root
A node of type T which is the root of the JSON document

โœ“ โ€” Level 1 โ€” T:nth-child(n)
A node of type T which is the nth child of an array parent

โœ“ โ€” Level 2 โ€” T:nth-last-child(n)
A node of type T which is the nth child of an array parent counting from the end

โœ“ โ€” Level 1 โ€” T:first-child
A node of type T which is the first child of an array parent (equivalent to T:nth-child(1))

โœ“ โ€” Level 2 โ€” T:last-child
A node of type T which is the last child of an array parent (equivalent to T:nth-last-child(1))

โœ“ โ€” Level 2 โ€” T:only-child
A node of type T which is the only child of an array parent

โœ“ โ€” Level 2 โ€” T:empty
A node of type T which is an array or object with no child

โœ“ โ€” Level 1 โ€” T U
A node of type U with an ancestor of type T

โœ“ โ€” Level 1 โ€” T > U
A node of type U with a parent of type T

โœ— โ€” Level 2 โ€” T ~ U
A node of type U with a sibling of type T

โœ“ โ€” Level 1 โ€” S1, S2
Any node which matches either selector S1 or S2

โœ— โ€” Level 3 โ€” T:has(S)
A node of type T which has a child node satisfying the selector S

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with Rakefile or version. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2011 Simon Menke. See LICENSE for details.

More Repositories

1

webrtc

WebRTC for Go
Go
54
star
2

go-nat

NAT port mapping library for Go
Go
43
star
3

language-hcl

A grammar for the HashiCorp Configuration Language.
CoffeeScript
12
star
4

gopkg-cc

Import Go packages from branches or tags.
CSS
8
star
5

prerender

Use prerender.io with Go
Go
7
star
6

jsonschema

A Go implemenation of json-schema.
Go
7
star
7

heroku-keepalive

Go
4
star
8

httpmiddlewarevet

Go
4
star
9

options

Self documenting CLI options parser for Go
Go
4
star
10

zettalm

Go code to build linear regression models on zettabytes of data
Go
3
star
11

go-git-remote-helper

Go
3
star
12

helsinki-blog

Frozen Rails - Mini Blog
3
star
13

switchboard

Go
2
star
14

be-data-api

API client for data.be
Ruby
2
star
15

ecdh

Elliptic curve Diffieโ€“Hellman key sharing for Golang
Go
2
star
16

eccp

Elliptic Curve Compressed Point (un-)marshaler for Golang
Go
2
star
17

butler-standalone

A simple web crawler for generating sitemaps and reporting errors.
Go
2
star
18

etaps

Super simple CLI for taps
Ruby
2
star
19

jquery.viewport.js

jQuery plugin for getting elements above, in or below the viewport
2
star
20

docker-golang

Shell
1
star
21

forklift

Power tools for Heroku
Go
1
star
22

go-cli

A More advanced CLI options parsing solution.
Go
1
star
23

secp160r1

Parameters for the secp160r1 Elliptic curve for Golang
Go
1
star
24

go-shellwords

Split and join shell words in go
Go
1
star
25

go-pool

Go resource pooling with support for over-leasing
Go
1
star
26

schemata.js

ES6 ready JSON-Schema validator
JavaScript
1
star
27

tar-utils

Go
1
star
28

simplex

Go
1
star
29

docker-fail

Deliberately failing docker image
Shell
1
star
30

term-presenter

Go
1
star
31

go-dht

Go
1
star
32

activerecord-i18n

I18n for ActiveRecord doesn't have to be complicated.
Ruby
1
star
33

go-util

Go
1
star
34

terraform-provider-kubernetes

Go
1
star
35

oapx

Go
1
star
36

taskr

Go
1
star
37

static-v8-binaries

Shell
1
star