Skip to content

specifying a comma-separated list of array indexes throws an Exception #28

@christopheraranda

Description

@christopheraranda

According to the README, a comma-separated list of array indexes may be specified in a JsonPath.

Syntax Meaning
[n] array index (may be comma-separated list)

However, when attempting to use multiple indexes, the following exception is thrown:

def p_error(self, t):
>       raise Exception('Parse error at %s:%s near token %s (%s)' % (t.lineno, t.col, t.value, t.type))
E       Exception: Parse error at 1:14 near token , (,)

The following code can be used to reproduce the issue:

import unittest

from jsonpath_ng.ext import parse

TEST_DATA = {
    'store': {
        'book': [
            {
                'category': 'reference',
                'author': 'Nigel Rees',
                'title': 'Sayings of the Century',
                'price': 8.95
            },
            {
                'category': 'fiction',
                'author': 'Evelyn Waugh',
                'title': 'Sword of Honour',
                'price': 12.99
            },
            {
                'category': 'fiction',
                'author': 'Herman Melville',
                'title': 'Moby Dick',
                'isbn': '0-553-21311-3',
                'price': 8.99
            }
        ],
        'bicycle': {
            'color': 'red',
            'price': 19.95
        }
    }
}


class Test(unittest.TestCase):

    def test(self):
        path = "$.store.book[0,2].title"
        values = [match.value for match in parse(path).find(TEST_DATA)]
        self.assertEqual(values, ['Sayings of the Century', 'Moby Dick'])

I have verified that the path is valid on various JsonPath evaluators.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions