GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - fd/json_select: CSS-like selectors for JSON (Ruby implementation).

BranchesTags
Open more actions menu

Latest commit

 

History

29 Commits
29 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
spec
spec
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
.travis.yml
.travis.yml
 
 
Gemfile
Gemfile
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
Rakefile
Rakefile
 
 
json_select.gemspec
json_select.gemspec
 
 

Repository files navigation

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.

About

CSS-like selectors for JSON (Ruby implementation).

jsonselect.org

Resources

Readme
MIT license
Activity

Stars

113 stars

Watchers

4 watching

Forks

5 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.