0

I'm using JSON Path to extract a some data from a json object.

The object looks like this:

{
   "properties":
      { 
         "random_field": "abc",
         "max value": "£35,900"
      }
}

My JSON path looks like this:

insert into display_paths (type,name,jsonpath) values ('type','Value (£)','$.properties.[''max value'']');

Annoyingly, this is returning the value without the ',', instead replacing it with a space:

Value (£): £35 900

Has anyone had a similar issue? Potentially it is a front end issue as opposed to a json path issue?

Ezequiel
  • 3,477
  • 1
  • 20
  • 28
nimgwfc
  • 1,294
  • 1
  • 12
  • 30
  • I've tested `$.properties.[max value]` in https://jsonpath.com/ and it works properly. Maybe it is a render issue. – Ezequiel Jan 17 '20 at 11:48

1 Answers1

1

Note: Consider the risk of SQL injection when inserting unprepared data from external sources into an SQL statement like in your example. Read about prepared statements, using them can prevent this.


About the jsonpath issue, looks like a quoting issue with your code. Check this working example:

import json
from jsonpath import jsonpath


data = json.loads('''
{
   "properties":
      { 
         "random_field": "abc",
         "max value": "£35,900"
      }
}
''')


query = "$.properties.['max value']"
# Note that this works too
query = "$.properties.[max value]"

print(data)
print(jsonpath(data, query))

Output:

{'properties': {'random_field': 'abc', 'max value': '£35,900'}}
['£35,900']

PS: pip install jsonpath must be run for this example to work.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266