Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private[this] object JsonPathParser extends RegexParsers {
// parse `.name` or `['name']` child expressions
def named: Parser[List[PathInstruction]] =
for {
name <- '.' ~> "[^\\.\\[]+".r | "[\\'" ~> "[^\\'\\?]+" <~ "\\']"
name <- '.' ~> "[^\\.\\[]+".r | "['" ~> "[^\\'\\?]+".r <~ "']"
} yield {
Key :: Named(name) :: Nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
"""{"price":19.95,"color":"red"}""")
}

test("$['store'].bicycle") {
checkEvaluation(
GetJsonObject(Literal(json), Literal("$['store'].bicycle")),
"""{"price":19.95,"color":"red"}""")
}

test("$.store['bicycle']") {
checkEvaluation(
GetJsonObject(Literal(json), Literal("$.store['bicycle']")),
"""{"price":19.95,"color":"red"}""")
}

test("$['store']['bicycle']") {
checkEvaluation(
GetJsonObject(Literal(json), Literal("$['store']['bicycle']")),
"""{"price":19.95,"color":"red"}""")
}

test("$['key with spaces']") {
checkEvaluation(GetJsonObject(
Literal("""{ "key with spaces": "it works" }"""), Literal("$['key with spaces']")),
"it works")
}

test("$.store.book") {
checkEvaluation(
GetJsonObject(Literal(json), Literal("$.store.book")),
Expand Down