jsonpath-python


Namejsonpath-python JSON
Version 1.0.6 PyPI version JSON
download
home_pagehttps://github.com/zhangxianbing/jsonpath-python
SummaryA more powerful JSONPath implementation in modern python
upload_time2022-03-14 02:35:01
maintainer
docs_urlNone
authorzhangxianbing
requires_python>=3.6
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            - [jsonpath-python](#jsonpath-python)
  - [Features](#features)
  - [JSONPath Syntax](#jsonpath-syntax)
    - [Operators](#operators)
    - [Examples](#examples)
      - [Select Fields](#select-fields)
      - [Recursive Descent](#recursive-descent)
      - [Slice](#slice)
      - [Filter Expression](#filter-expression)
      - [Sorter Expression](#sorter-expression)
      - [Field-Extractor Expression](#field-extractor-expression)
    - [Appendix: Example JSON data:](#appendix-example-json-data)
  - [Todo List](#todo-list)

# jsonpath-python

A more powerful JSONPath implementation in modern python.

## Features

- [x] **Light. (No need to install third-party dependencies.)**
- [x] **Support filter operator, including multi-selection, inverse-selection filtering.**
- [x] **Support sorter operator, including sorting by multiple fields, ascending and descending order.**
- [x] Support basic semantics of JSONPath.
- [x] Support output modes: VALUE, PATH.
- [ ] Support embedded syntax.
- [ ] Support user-defined function.
- [ ] Support parent operator.

## Installation

```bash
pip install jsonpath-python

# import
>>> from jsonpath import JSONPath
```

## JSONPath Syntax

The JSONPath syntax in this project borrows from [JSONPath - XPath for JSON](http://goessner.net/articles/JSONPath/) and is **modified** and **extended** on it.

### Operators

| Operator         | Description                                                                  |
| ---------------- | ---------------------------------------------------------------------------- |
| `$`              | the root object/element                                                      |
| `@`              | the current object/element                                                   |
| `.` or `[]`      | child operator                                                               |
| `..`             | recursive descent                                                            |
| `*`              | wildcard                                                                     |
| `''`             | (Experimental) wrap field with special character: dots(`.`) and space (` `). |
| `start:end:step` | array slice operator (It's same as the slice in python)                      |
| `?()`            | applies a filter expression                                                  |
| `/()`            | applies a sorter expression                                                  |
| `()`             | applies a field-extractor expression                                         |

### Examples

Before running the following example, please import this module and the example data:

```python
>>> from jsonpath import JSONPath

# For the data used in the following example, please refer to the Appendix part.
```

#### Select Fields

Select a field:

```python
>>> JSONPath("$.book").parse(data)
[[{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}, {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}, {'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99, 'brand': {'version': 'v1.0.3'}}]]
>>> JSONPath("$[book]").parse(data)
[[{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}, {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}, {'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99, 'brand': {'version': 'v1.0.3'}}]]
```

(**Experimental**) Select a field with special character: dots(`.`) and space (` `).

```python
>>> JSONPath("$.'a.b c'").parse(data)
['a.b c']
>>> JSONPath("$['a.b c']").parse(data)
['a.b c']
```

Select multiple fields:

```python
>>> JSONPath("$[bicycle,scores]").parse(data)
[{'color': 'red', 'price': 19.95}, {'math': {'score': 100, 'avg': 60}, 'english': {'score': 95, 'avg': 80}, 'physic': {'score': 90, 'avg': 70}, 'chemistry': {'score': 85, 'avg': 80}, 'chinese': {'score': 60, 'avg': 75}}]
```

Select all fields using wildcard `*`:

```python
>>> JSONPath("$.*").parse(data)
['a.b c', [{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}, {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}, {'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99, 'brand': {'version': 'v1.0.3'}}], {'color': 'red', 'price': 19.95}, {'math': {'score': 100, 'avg': 60}, 'english': {'score': 95, 'avg': 80}, 'physic': {'score': 90, 'avg': 70}, 'chemistry': {'score': 85, 'avg': 80}, 'chinese': {'score': 60, 'avg': 75}}]
```

#### Recursive Descent

```python
>>> JSONPath("$..price").parse(data)
[8.95, 12.99, 8.99, 22.99, 19.95]
```

#### Slice

Support python-like slice.

```python
>>> JSONPath("$.book[1:3]").parse(data)
[{'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}]
>>> JSONPath("$.book[1:-1]").parse(data)
[{'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}]
>>> JSONPath("$.book[0:-1:2]").parse(data)
[{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}]
>>> JSONPath("$.book[-1:1]").parse(data)
[]
>>> JSONPath("$.book[-1:-11:3]").parse(data)
[]
>>> JSONPath("$.book[:]").parse(data)
[{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}, {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}, {'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99, 'brand': {'version': 'v1.0.3'}}]
>>> JSONPath("$.book[::-1]").parse(data)
[{'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99, 'brand': {'version': 'v1.0.3'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}, {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}]

```

#### Filter Expression

Support all python comparison operators (`==`, `!=`, `<`, `>`, `>=`, `<=`), python membership operators (`in`, `not in`), python logical operators (`and`, `or`, `not`).

```python
>>> JSONPath("$.book[?(@.price>8 and @.price<9)].price").parse(data)
[8.95, 8.99]
>>> JSONPath('$.book[?(@.category=="reference")].category').parse(data)
['reference']
>>> JSONPath('$.book[?(@.category!="reference" and @.price<9)].title').parse(data)
['Moby Dick']
>>> JSONPath('$.book[?(@.author=="Herman Melville" or @.author=="Evelyn Waugh")].author').parse(data)
['Evelyn Waugh', 'Herman Melville']
```

`Note`: You must use double quote(`""`) instead of single quote(`''`) to wrap the compared string, because single quote(`''`) has another usage in this JSONPath syntax .

#### Sorter Expression

Support sorting by multiple fields (using operator `,`) and reverse sort (using operator `~`).

```python
>>> JSONPath("$.book[/(price)].price").parse(data)
[8.95, 8.99, 12.99, 22.99]
>>> JSONPath("$.book[/(~price)].price").parse(data)
[22.99, 12.99, 8.99, 8.95]
>>> JSONPath("$.book[/(category,price)].price").parse(data)
[8.99, 12.99, 22.99, 8.95]
>>> JSONPath("$.book[/(brand.version)].brand.version").parse(data)
['v0.0.1', 'v1.0.0', 'v1.0.2', 'v1.0.3']
>>> JSONPath("$.scores[/(score)].score").parse(data)
[60, 85, 90, 95, 100]
```

#### Field-Extractor Expression

Using `(field1,field2,…,filedn)` after a dict object to extract its fields.

```python
>>> JSONPath("$.scores[/(score)].(score)").parse(data)
[{'score': 60}, {'score': 85}, {'score': 90}, {'score': 95}, {'score': 100}]
>>> JSONPath("$.book[/(category,price)].(title,price)").parse(data)
[{'title': 'Moby Dick', 'price': 8.99}, {'title': 'Sword of Honour', 'price': 12.99}, {'title': 'The Lord of the Rings', 'price': 22.99}, {'title': 'Sayings of the Century', 'price': 8.95}]
```

### Appendix: Example JSON data:

```python
data = {
    "a.b c": "a.b c",
    "book": [
        {
            "category": "reference",
            "author": "Nigel Rees",
            "title": "Sayings of the Century",
            "price": 8.95,
            "brand": {
                "version": "v1.0.0"
            }
        },
        {
            "category": "fiction",
            "author": "Evelyn Waugh",
            "title": "Sword of Honour",
            "price": 12.99,
            "brand": {
                "version": "v0.0.1"
            }
        },
        {
            "category": "fiction",
            "author": "Herman Melville",
            "title": "Moby Dick",
            "isbn": "0-553-21311-3",
            "price": 8.99,
            "brand": {
                "version": "v1.0.2"
            }
        },
        {
            "category": "fiction",
            "author": "J. R. R. Tolkien",
            "title": "The Lord of the Rings",
            "isbn": "0-395-19395-8",
            "price": 22.99,
            "brand": {
                "version": "v1.0.3"
            }
        }
    ],
    "bicycle": {
        "color": "red",
        "price": 19.95
    },
    "scores": {
        "math": {
            "score": 100,
            "avg": 60
        },
        "english": {
            "score": 95,
            "avg": 80
        },
        "physic": {
            "score": 90,
            "avg": 70
        },
        "chemistry": {
            "score": 85,
            "avg": 80
        },
        "chinese": {
            "score": 60,
            "avg": 75
        }
    }
}
```

## Todo List

- Syntax and character set (refer to k8s)

> The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character (`[a-z0-9A-Z]`) with dashes (`-`), underscores (`_`), dots (`.`), and alphanumerics between.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zhangxianbing/jsonpath-python",
    "name": "jsonpath-python",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "zhangxianbing",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/b5/49/e582e50b0c54c1b47e714241c4a4767bf28758bf90212248aea8e1ce8516/jsonpath-python-1.0.6.tar.gz",
    "platform": null,
    "description": "- [jsonpath-python](#jsonpath-python)\n  - [Features](#features)\n  - [JSONPath Syntax](#jsonpath-syntax)\n    - [Operators](#operators)\n    - [Examples](#examples)\n      - [Select Fields](#select-fields)\n      - [Recursive Descent](#recursive-descent)\n      - [Slice](#slice)\n      - [Filter Expression](#filter-expression)\n      - [Sorter Expression](#sorter-expression)\n      - [Field-Extractor Expression](#field-extractor-expression)\n    - [Appendix: Example JSON data:](#appendix-example-json-data)\n  - [Todo List](#todo-list)\n\n# jsonpath-python\n\nA more powerful JSONPath implementation in modern python.\n\n## Features\n\n- [x] **Light. (No need to install third-party dependencies.)**\n- [x] **Support filter operator, including multi-selection, inverse-selection filtering.**\n- [x] **Support sorter operator, including sorting by multiple fields, ascending and descending order.**\n- [x] Support basic semantics of JSONPath.\n- [x] Support output modes: VALUE, PATH.\n- [ ] Support embedded syntax.\n- [ ] Support user-defined function.\n- [ ] Support parent operator.\n\n## Installation\n\n```bash\npip install jsonpath-python\n\n# import\n>>> from jsonpath import JSONPath\n```\n\n## JSONPath Syntax\n\nThe JSONPath syntax in this project borrows from [JSONPath - XPath for JSON](http://goessner.net/articles/JSONPath/) and is **modified** and **extended** on it.\n\n### Operators\n\n| Operator         | Description                                                                  |\n| ---------------- | ---------------------------------------------------------------------------- |\n| `$`              | the root object/element                                                      |\n| `@`              | the current object/element                                                   |\n| `.` or `[]`      | child operator                                                               |\n| `..`             | recursive descent                                                            |\n| `*`              | wildcard                                                                     |\n| `''`             | (Experimental) wrap field with special character: dots(`.`) and space (` `). |\n| `start:end:step` | array slice operator (It's same as the slice in python)                      |\n| `?()`            | applies a filter expression                                                  |\n| `/()`            | applies a sorter expression                                                  |\n| `()`             | applies a field-extractor expression                                         |\n\n### Examples\n\nBefore running the following example, please import this module and the example data:\n\n```python\n>>> from jsonpath import JSONPath\n\n# For the data used in the following example, please refer to the Appendix part.\n```\n\n#### Select Fields\n\nSelect a field:\n\n```python\n>>> JSONPath(\"$.book\").parse(data)\n[[{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}, {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}, {'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99, 'brand': {'version': 'v1.0.3'}}]]\n>>> JSONPath(\"$[book]\").parse(data)\n[[{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}, {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}, {'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99, 'brand': {'version': 'v1.0.3'}}]]\n```\n\n(**Experimental**) Select a field with special character: dots(`.`) and space (` `).\n\n```python\n>>> JSONPath(\"$.'a.b c'\").parse(data)\n['a.b c']\n>>> JSONPath(\"$['a.b c']\").parse(data)\n['a.b c']\n```\n\nSelect multiple fields:\n\n```python\n>>> JSONPath(\"$[bicycle,scores]\").parse(data)\n[{'color': 'red', 'price': 19.95}, {'math': {'score': 100, 'avg': 60}, 'english': {'score': 95, 'avg': 80}, 'physic': {'score': 90, 'avg': 70}, 'chemistry': {'score': 85, 'avg': 80}, 'chinese': {'score': 60, 'avg': 75}}]\n```\n\nSelect all fields using wildcard `*`:\n\n```python\n>>> JSONPath(\"$.*\").parse(data)\n['a.b c', [{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}, {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}, {'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99, 'brand': {'version': 'v1.0.3'}}], {'color': 'red', 'price': 19.95}, {'math': {'score': 100, 'avg': 60}, 'english': {'score': 95, 'avg': 80}, 'physic': {'score': 90, 'avg': 70}, 'chemistry': {'score': 85, 'avg': 80}, 'chinese': {'score': 60, 'avg': 75}}]\n```\n\n#### Recursive Descent\n\n```python\n>>> JSONPath(\"$..price\").parse(data)\n[8.95, 12.99, 8.99, 22.99, 19.95]\n```\n\n#### Slice\n\nSupport python-like slice.\n\n```python\n>>> JSONPath(\"$.book[1:3]\").parse(data)\n[{'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}]\n>>> JSONPath(\"$.book[1:-1]\").parse(data)\n[{'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}]\n>>> JSONPath(\"$.book[0:-1:2]\").parse(data)\n[{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}]\n>>> JSONPath(\"$.book[-1:1]\").parse(data)\n[]\n>>> JSONPath(\"$.book[-1:-11:3]\").parse(data)\n[]\n>>> JSONPath(\"$.book[:]\").parse(data)\n[{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}, {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}, {'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99, 'brand': {'version': 'v1.0.3'}}]\n>>> JSONPath(\"$.book[::-1]\").parse(data)\n[{'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99, 'brand': {'version': 'v1.0.3'}}, {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99, 'brand': {'version': 'v1.0.2'}}, {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99, 'brand': {'version': 'v0.0.1'}}, {'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95, 'brand': {'version': 'v1.0.0'}}]\n\n```\n\n#### Filter Expression\n\nSupport all python comparison operators (`==`, `!=`, `<`, `>`, `>=`, `<=`), python membership operators (`in`, `not in`), python logical operators (`and`, `or`, `not`).\n\n```python\n>>> JSONPath(\"$.book[?(@.price>8 and @.price<9)].price\").parse(data)\n[8.95, 8.99]\n>>> JSONPath('$.book[?(@.category==\"reference\")].category').parse(data)\n['reference']\n>>> JSONPath('$.book[?(@.category!=\"reference\" and @.price<9)].title').parse(data)\n['Moby Dick']\n>>> JSONPath('$.book[?(@.author==\"Herman Melville\" or @.author==\"Evelyn Waugh\")].author').parse(data)\n['Evelyn Waugh', 'Herman Melville']\n```\n\n`Note`: You must use double quote(`\"\"`) instead of single quote(`''`) to wrap the compared string, because single quote(`''`) has another usage in this JSONPath syntax .\n\n#### Sorter Expression\n\nSupport sorting by multiple fields (using operator `,`) and reverse sort (using operator `~`).\n\n```python\n>>> JSONPath(\"$.book[/(price)].price\").parse(data)\n[8.95, 8.99, 12.99, 22.99]\n>>> JSONPath(\"$.book[/(~price)].price\").parse(data)\n[22.99, 12.99, 8.99, 8.95]\n>>> JSONPath(\"$.book[/(category,price)].price\").parse(data)\n[8.99, 12.99, 22.99, 8.95]\n>>> JSONPath(\"$.book[/(brand.version)].brand.version\").parse(data)\n['v0.0.1', 'v1.0.0', 'v1.0.2', 'v1.0.3']\n>>> JSONPath(\"$.scores[/(score)].score\").parse(data)\n[60, 85, 90, 95, 100]\n```\n\n#### Field-Extractor Expression\n\nUsing `(field1,field2,\u2026,filedn)` after a dict object to extract its fields.\n\n```python\n>>> JSONPath(\"$.scores[/(score)].(score)\").parse(data)\n[{'score': 60}, {'score': 85}, {'score': 90}, {'score': 95}, {'score': 100}]\n>>> JSONPath(\"$.book[/(category,price)].(title,price)\").parse(data)\n[{'title': 'Moby Dick', 'price': 8.99}, {'title': 'Sword of Honour', 'price': 12.99}, {'title': 'The Lord of the Rings', 'price': 22.99}, {'title': 'Sayings of the Century', 'price': 8.95}]\n```\n\n### Appendix: Example JSON data:\n\n```python\ndata = {\n    \"a.b c\": \"a.b c\",\n    \"book\": [\n        {\n            \"category\": \"reference\",\n            \"author\": \"Nigel Rees\",\n            \"title\": \"Sayings of the Century\",\n            \"price\": 8.95,\n            \"brand\": {\n                \"version\": \"v1.0.0\"\n            }\n        },\n        {\n            \"category\": \"fiction\",\n            \"author\": \"Evelyn Waugh\",\n            \"title\": \"Sword of Honour\",\n            \"price\": 12.99,\n            \"brand\": {\n                \"version\": \"v0.0.1\"\n            }\n        },\n        {\n            \"category\": \"fiction\",\n            \"author\": \"Herman Melville\",\n            \"title\": \"Moby Dick\",\n            \"isbn\": \"0-553-21311-3\",\n            \"price\": 8.99,\n            \"brand\": {\n                \"version\": \"v1.0.2\"\n            }\n        },\n        {\n            \"category\": \"fiction\",\n            \"author\": \"J. R. R. Tolkien\",\n            \"title\": \"The Lord of the Rings\",\n            \"isbn\": \"0-395-19395-8\",\n            \"price\": 22.99,\n            \"brand\": {\n                \"version\": \"v1.0.3\"\n            }\n        }\n    ],\n    \"bicycle\": {\n        \"color\": \"red\",\n        \"price\": 19.95\n    },\n    \"scores\": {\n        \"math\": {\n            \"score\": 100,\n            \"avg\": 60\n        },\n        \"english\": {\n            \"score\": 95,\n            \"avg\": 80\n        },\n        \"physic\": {\n            \"score\": 90,\n            \"avg\": 70\n        },\n        \"chemistry\": {\n            \"score\": 85,\n            \"avg\": 80\n        },\n        \"chinese\": {\n            \"score\": 60,\n            \"avg\": 75\n        }\n    }\n}\n```\n\n## Todo List\n\n- Syntax and character set (refer to k8s)\n\n> The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character (`[a-z0-9A-Z]`) with dashes (`-`), underscores (`_`), dots (`.`), and alphanumerics between.\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A more powerful JSONPath implementation in modern python",
    "version": "1.0.6",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "c74ba73cfde7efd6c4fa8c07740acae6",
                "sha256": "1e3b78df579f5efc23565293612decee04214609208a2335884b3ee3f786b575"
            },
            "downloads": -1,
            "filename": "jsonpath_python-1.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c74ba73cfde7efd6c4fa8c07740acae6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7552,
            "upload_time": "2022-03-14T02:34:59",
            "upload_time_iso_8601": "2022-03-14T02:34:59.754916Z",
            "url": "https://files.pythonhosted.org/packages/16/8a/d63959f4eff03893a00e6e63592e3a9f15b9266ed8e0275ab77f8c7dbc94/jsonpath_python-1.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "fa0caa67045d5d7da0d04db23e9cd83f",
                "sha256": "dd5be4a72d8a2995c3f583cf82bf3cd1a9544cfdabf2d22595b67aff07349666"
            },
            "downloads": -1,
            "filename": "jsonpath-python-1.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "fa0caa67045d5d7da0d04db23e9cd83f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 18121,
            "upload_time": "2022-03-14T02:35:01",
            "upload_time_iso_8601": "2022-03-14T02:35:01.877195Z",
            "url": "https://files.pythonhosted.org/packages/b5/49/e582e50b0c54c1b47e714241c4a4767bf28758bf90212248aea8e1ce8516/jsonpath-python-1.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-03-14 02:35:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "zhangxianbing",
    "github_project": "jsonpath-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "jsonpath-python"
}
        
Elapsed time: 0.01463s