Giter Site home page Giter Site logo

json-to-flat-table's Introduction

JsonPath with support for Flat Table Generation

Build Status Coverage Status Latest Stable Version License

This is a JSONPath implementation for PHP.

This implementation features all elements in the specification except the () operator (in the spcecification there is the $..a[(@.length-1)], but this can be achieved with $..a[-1] and the latter is simpler).

On top of this it implements some extended features:

  • Regex match comparisons (p.e. $.store.book[?(@.author =~ /.*Tolkien/)])
  • For the child operator [] there is no need to surround child names with quotes (p.e. $.[store][book, bicycle]) except if the name of the field is a non-valid javascript variable name.
  • .length can be used to get the length of a string, get the length of an array and to check if a node has children.

Features

This implementation has the following features:

  • Convert json tree into a flat table using the set of jsonpath stings.

JsonPath Example

Consider the following json:

{ "store": {
    "name":"My Store",
    "book": [
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95,
        "available": true,
        "authors": ["Nigel Rees"]
      },
      { "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99,
        "available": false,
        "authors": []
      },
      { "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99,
        "available": true,
        "authors": ["Nigel Rees"]
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99,
        "available": false,
        "authors": ["Evelyn Waugh", "J. R. R. Tolkien"]
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95,
      "available": true,
      "model": null,
      "sku-number": "BCCLE-0001-RD"
    },
    "bicycleSet": [{
      "color": "red",
      "price": 19.95,
      "available": true,
      "model": null,
      "sku-number": "BCCLE-0001-RD"
    },{
      "color": "green",
      "price": 19.75,
      "available": false,
      "model": null,
      "sku-number": "RCADF-0002-CQ"
    }]
  },
  "authors": [
    "Nigel Rees",
    "Evelyn Waugh",
    "Herman Melville",
    "J. R. R. Tolkien"
  ],
  "Bike models": [
    1,
    2,
    3
  ]
}

JsonPath => Result

[$.store.bicycle.price]

19.95

[$.store.name,$.store.bicycle.price,$.store.bicycle.sku-number]

My Store 19.95 BCCLE-0001-RD

[$.store.book[*].price,$.store.book[*].price,$.store.book[*].authors[*],$.store.book[*].title,$.store.name]

8.95 8.95 Nigel Rees Sayings of the Century My Store
12.99 12.99 null Sword of Honour My Store
8.99 8.99 Nigel Rees Moby Dick My Store
22.99 22.99 Evelyn Waugh The Lord of the Rings My Store
22.99 22.99 J. R. R. Tolkien The Lord of the Rings My Store

Usage

$json = '{... your json as string ...}';
$jsonPath = '[$.your.jsonpath.1,$.your.jsonpath.2]';

$jsonObject = new JsonObject($json);
$result = $jsonObject->getTable($jsonPath);

json-to-flat-table's People

Contributors

fayway avatar galbar avatar javibravo avatar kirill533 avatar lksnmnn avatar motanelu avatar richardkeen avatar sergeynikolaev avatar

Stargazers

 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.