Code Monkey home page Code Monkey logo

json-path's Introduction

JSON::Path Build Status

The JSONPath query language was designed for indexing into JSON documents. It plays the same role as XPath does for XML documents.

This module implements JSON::Path. However, it is not restricted to working on JSON input. In fact, it will happily work over any data structure made up of arrays and hashes.

Synopsis

# Example data.
my $data = {
    kitchen => {
        drawers => [
            { knife => '๐Ÿ”ช' },
            { glass => '๐Ÿท' },
            { knife => '๐Ÿ—ก๏ธ' },
        ]
    }
};

# A query
my $jp = JSON::Path.new('$.kitchen.drawers[*].knife');

# The first result
dd $jp.value($data);    # "๐Ÿ”ช"

# All results.
dd $jp.values($data);   # ("๐Ÿ”ช", "๐Ÿ—ก๏ธ").Seq

# All paths where the results were found.
dd $jp.paths($data);    # ("\$.kitchen.drawers[0].knife",
                        #  "\$.kitchen.drawers[2].knife").Seq

# Interleaved paths and values.
dd $jp.paths-and-values($data); # ("\$.kitchen.drawers[0].knife", "๐Ÿ”ช",
                                #  "\$.kitchen.drawers[2].knife", "๐Ÿ—ก๏ธ").Seq

Query Syntax Summary

The following syntax is supported:

$           root node
.key        index hash key
['key']     index hash key
[2]         index array element
[0,1]       index array slice
[4:5]       index array range
[:5]        index from the beginning
[-3:]       index to the end
.*          index all elements
[*]         index all elements
[?(expr)]   filter on (Perl 6) expression
..key       search all descendants for hash key

A query that is not rooted from $ or specified using .. will be evaluated from the document root (that is, same as an explicit $ at the start).

json-path's People

Contributors

jnthn avatar moritz avatar zoffixznet avatar fco avatar szabgab avatar samcv avatar ugexe avatar

Watchers

James Cloos avatar tony-o avatar  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.