1

I want to write the xpath for a json field which is having white spaces in it.

[    
    {"name":"Ram", "emai ld":"ram@gmail.com", "age":23},    
    {"name":"Shyam", "email id":"shyam23@gmail.com", "age":28}
]

I tried as below to get the email id:

?1?email id

When I searched in open source I got to know this is not possible in Xpath 3.1. Xpath 4.0 supports the above as

?1?'email id'

Can somebody helps how I can use Xpath 4.0? Meaning any dependency that I need to add?

Michael Kay
  • 156,231
  • 11
  • 92
  • 164

2 Answers2

1

You need to put the string literal in parentheses:

?1?('email id')
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
1

Or just call the map with e.g. ?1('email id').

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • @mads-hansen, my reading of the grammar would consider my example being a dynamic function call https://www.w3.org/TR/xpath-31/#id-dynamic-function-invocation, not a parenthesized expression. – Martin Honnen Aug 08 '23 at 15:10
  • https://www.w3.org/TR/xpath-31/#id-lookup `[54] KeySpecifier ::= NCName | IntegerLiteral | ParenthesizedExpr | "*" ` – Mads Hansen Aug 08 '23 at 15:46
  • 1
    That is what Michael Kay has suggested with his example of e.g. `?1?('email id')`, mine is a dynamic function call where `('email id')` is the sole function argument. – Martin Honnen Aug 08 '23 at 15:54
  • doh, I missed that it was missing the `?` – Mads Hansen Aug 08 '23 at 16:01