adriank / ObjectPath

The agile query language for semi-structured data
http://objectpath.org
MIT License
380 stars 93 forks source link

json_normalize usage #90

Closed montge closed 2 years ago

montge commented 5 years ago

Recommendation of updating the documentation to include a more in-depth example. Especially focused on getting formats that are pandas friendly. Specifically one that deals with two scenarios.

  1. json_normalize one would provide an example of how to connect to other functions in pandas
  2. Getting things back to json format with the generator

Something like the following on the first one. The idea is to show that you can connect to other functions.

data_o = json_normalize(tree.execute("$.data.groups.*[@.type is 'object']"),'objectRules',['id'])

For the second one something like following which might go with a generalized improvement in documentation around the utils.

data_o = utils.json_ext.dumps(tree_output)
data_l = json.loads(data_o)

On the latter one it might be worth adding a function, just because it seems to take an extra step that I would run every time. Although the naming convention might be different. This is basically to deal with the generator. I know it's just two lines of code, but it seems like it would help make things a bit clearer to improve usability.

def objectpath_to_json(g):
    d = utils.json_ext.dumps(g)
    return json.loads(d)

BTW, the reason I ended up down this path is the py2JSON and printJSON weren't as helpful as I needed them for the things I needed.

adriank commented 4 years ago

I'm not familiar with Pandas at all. If you have an idea of such documentation, please make a PR to gh-pages branch.