Rooyca / obsidian-api-request

Obsidian plugin that allows you to make requests to API's and receive responses in codeblocks or store them in localStorage.
https://rooyca.github.io/obsidian-api-request/
MIT License
78 stars 4 forks source link

Nested Data #2

Closed eb2ai closed 10 months ago

eb2ai commented 10 months ago

I would like to get information that is nested inside the json.

Example https://api.chess.com/pub/player/hikaru/stats

Returns

json:: {"chess_daily":{"last":{"rating":2239,"date":1687457553,"rd":103},"best":{"rating":2464,"date":1397136740,"game":"https://www.chess.com/game/daily/84604826"},"record":{"win":73,"loss":11,"draw":4,"time_per_move":32755,"timeout_percent":0}},"chess960_daily":{"last":{"rating":1231,"date":1444458214,"rd":230},"best":{"rating":1489,"date":1397073007,"game":"https://www.chess.com/game/daily/87191830"},"record":{"win":1,"loss":2,"draw":0,"time_per_move":32755,"timeout_percent":0}},"chess_rapid":{"last":{"rating":2781,"date":1687191247,"rd":62},"best":{"rating":2927,"date":1645902514,"game":"https://www.chess.com/game/live/61144117987"},"record":{"win":156,"loss":39,"draw":157}},"chess_bullet":{"last":{"rating":3326,"date":1691866712,"rd":30},"best":{"rating":3570,"date":1605136047,"game":"https://www.chess.com/game/live/5710095242"},"record":{"win":11141,"loss":1590,"draw":692}},"chess_blitz":{"last":{"rating":3214,"date":1692140808,"rd":35},"best":{"rating":3332,"date":1585690331,"game":"https://www.chess.com/game/live/59245152619"},"record":{"win":24907,"loss":4301,"draw":3315}},"fide":2814,"tactics":{"highest":{"rating":3427,"date":1667403710},"lowest":{"rating":695,"date":1389043648}},"puzzle_rush":{"best":{"total_attempts":126,"score":123},"daily":{"total_attempts":50,"score":48}}}

If Data to show in modal set to chess_daily it returns the subset of as expected.

json:: chess_daily : {"last":{"rating":2239,"date":1687457553,"rd":103},"best":{"rating":2464,"date":1397136740,"game":"https://www.chess.com/game/daily/84604826"},"record":{"win":73,"loss":11,"draw":4,"time_per_move":32755,"timeout_percent":0}}

I would like to be able to target chess_daily --> last --> rating

Rooyca commented 10 months ago

Good idea, I will try to add more ways to manipulate the response.

Rooyca commented 10 months ago

It's done... I have used the same format you used (chess_daily -> last -> rating) because I found it simpler than using a period (chess_daily.last.raiting) or square brackets (chess_daily[last][raiting]).

eb2ai commented 10 months ago

I appreciate it! I'm not getting it to work, though. I'm sure I'm missing something.

Screenshot by Dropbox Capture

eb2ai commented 10 months ago

I tried many variations of that with no luck. All them come back with undefined.

Rooyca commented 10 months ago

Did you update the plugin?

eb2ai commented 10 months ago

I'm embarrassed. I copied the files and didn't hit update ;)

Result = json:: rating : 2239

Super cool! Any way to remove "json::"?

Rooyca commented 10 months ago

You don't have to copy them manually, the plugin is on the Community Plugins.

Yes, I was thinking the same thing haha. I'll remove it in the next release.. I dont even remember why did I added in the first place.

For now, you could try with JSON insted of Variable, look at the settings.