Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "json_path" config option for nested data #16

Closed
laurentS opened this issue Mar 27, 2021 · 0 comments
Closed

Add "json_path" config option for nested data #16

laurentS opened this issue Mar 27, 2021 · 0 comments

Comments

@laurentS
Copy link
Contributor

I was trying to load a JSON file that looks like this (the actual file is here):

{
  "3166-1": [
    {
      "alpha_2": "AW",
      "alpha_3": "ABW",
      "name": "Aruba",
      "numeric": "533"
    },
    {
      "alpha_2": "AF",
      "alpha_3": "AFG",
      "name": "Afghanistan",
      "numeric": "004",
      "official_name": "Islamic Republic of Afghanistan"
    }
]}

which led to an error because the list of useful objects is nested under the 3166-1 key.
I was able to load the data by adding the following json_array = json_array['3166-1']just after

which tells me it should be possible to add a config option for the JSON handler (similar to delimiter for CSV handler for instance) that tells it where to look for the data. At a minimum, a string defining the key under which to get a list of items (so in my example, it could be like data_path: "3166-1"), but I imagine it should be possible to declare a full path, something like data_path: "section.subheading.one_more_level" so that it can grab items from arbitrarily deep in the tree.

I might give it a try in a PR if it makes sense to add something like this (I think so, I have a couple of use cases for it already 😉 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant