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

Filter results based on parent element name #21

Open
capgun-bandit opened this issue Mar 2, 2021 · 2 comments
Open

Filter results based on parent element name #21

capgun-bandit opened this issue Mar 2, 2021 · 2 comments

Comments

@capgun-bandit
Copy link

Awesome function! I'm having trouble getting my JSONPath query to work.

The data source is: https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY_ADJUSTED&symbol=IBM&apikey=demo

I'm trying to get all the of the "7. Dividend Amount" values by year. eg something like this:
=ImportJSONAPI("https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY_ADJUSTED&symbol=IBM&apikey=demo", "$[Monthly Adjusted Time Series].2019*.[7. dividend amount]", "@")

I can get all the Dividend Amounts with this:
=ImportJSONAPI("https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY_ADJUSTED&symbol=IBM&apikey=demo", "$[Monthly Adjusted Time Series].*.[7. dividend amount]", "@")

or an individual month also works:
=ImportJSONAPI("https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY_ADJUSTED&symbol=IBM&apikey=demo", "$[Monthly Adjusted Time Series].2021-02-26.[7. dividend amount]", "@")

But anytime I try to use a query to filter the date, it comes back empty. Thanks in advance for any input you have!

@qeet
Copy link
Owner

qeet commented Mar 2, 2021

To match only part of a property name you need to use the match function. Hopefully this should work for you:

=ImportJSONAPI("https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY_ADJUSTED&symbol=IBM&apikey=demo", "$[Monthly Adjusted Time Series][?(@property.match(/2019/))].[7. dividend amount]", "^~, @")

@capgun-bandit
Copy link
Author

Aha! Thank you so much!

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

2 participants