You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working on a project with Node.js and using “jsonpath-plus”. While using the module we’re facing certain issues-
Case-1: Special character ‘#’ when used in any of the keys in a json object and we try extracting it's value using “JSONPath” as shown in sample code below, it gives error as “TypeError: Cannot read property 'indexOf' of undefined”.
Case-2: In case when we use square brackets in any key i.e. ‘[’ or ‘]’, we’re not getting any error but rather the “console.log(resultobj)” statement in the above code gives “undefined” on the output window.
Case-3: While looking for different possible solutions I came to know that we’ll not get any error if we surround ‘#’ with parentheses i.e. ‘(’ and ‘)’ as shown in code below. Is this supposed to be a solution?
Case-4: We’re facing similar problems with other characters as well which are - ‘;’ , ‘^’ , ‘.’ , ‘~’
Code that reproduces problem here
Code for Case-1:
const { JSONPath } = require('jsonpath-plus')
function test(){
let object = {
"id!": "Hello World.",
"Email$987": "Rajat",
"recordType@34": "customer!",
"Name#23": "Test customer51-128721$" // Using '#' in a key
}
const initObj = {
path: '$.Name#23', // Path with same key
json: object,
resultType: 'all',
flatten: true,
wrap: false
}
const resultobj = JSONPath(initObj)
console.log(resultobj) // Error - "TypeError: Cannot read property 'indexOf' of undefined"
}
test()
Code for Case-2:
const { JSONPath } = require('jsonpath-plus')
function test(){
let object = {
"id!": "Hello World.",
"Email$987": "Rajat",
"recordType@34": "customer!",
'Name[23]': "Test customer51-128721$" // Using square brackets in key
}
const initObj = {
path: '$.Name[23]', // Path with same key
json: object,
resultType: 'all',
flatten: true,
wrap: false
}
const resultobj = JSONPath(initObj)
console.log(resultobj) // Output - "undefined"
}
test()
Code for Case-3:
const { JSONPath } = require('jsonpath-plus')
function test(){
let object = {
"id!": "Hello World.",
"Email$987": "Rajat",
"recordType@34": "customer!",
'Name(#)23': "Test customer51-128721$" // Using parentheses around '#'
}
const initObj = {
path: '$.Name(#)23', // Path with same key
json: object,
resultType: 'all',
flatten: true,
wrap: false
}
const resultobj = JSONPath(initObj)
console.log(resultobj) // No unexpected behaviour
}
test()
Console error or logs
Case-1 : TypeError: Cannot read property 'indexOf' of undefined
Hi @brettz9, Can you please look into the above issue and provide any escaping logic or workaround or fix for the above issue with special characters in the JSON data key names. Thanks.
As mentioned on the main page of the README, I am not actively maintaining this project, though I am accepting PRs. Feel free to submit a well-documented PR if you find an issue and your question is not answered by the README.
Hi Team,
I am working on a project with Node.js and using “jsonpath-plus”. While using the module we’re facing certain issues-
Case-1: Special character ‘#’ when used in any of the keys in a json object and we try extracting it's value using “JSONPath” as shown in sample code below, it gives error as “TypeError: Cannot read property 'indexOf' of undefined”.
Case-2: In case when we use square brackets in any key i.e. ‘[’ or ‘]’, we’re not getting any error but rather the “console.log(resultobj)” statement in the above code gives “undefined” on the output window.
Case-3: While looking for different possible solutions I came to know that we’ll not get any error if we surround ‘#’ with parentheses i.e. ‘(’ and ‘)’ as shown in code below. Is this supposed to be a solution?
Case-4: We’re facing similar problems with other characters as well which are - ‘;’ , ‘^’ , ‘.’ , ‘~’
Code that reproduces problem here
Code for Case-1:
Code for Case-2:
Code for Case-3:
Console error or logs
Case-1 : TypeError: Cannot read property 'indexOf' of undefined
Case-2: undefined
Case-3:
Expected behavior
Case-1: It should not give any error.
Case-2: It should give an output as it is giving in Case-3.
Case-3: It is working as expected.
Case-4: It should not give any error and give output as in Case-3.
Expected result
Case-1:
Case-2:
Environment (IMPORTANT)
Desktop**
Additional context
Please update with any solution or possible workaround.
The text was updated successfully, but these errors were encountered: