Group Abstract Group Abstract

Message Boards Message Boards

Navigating datasets?

Posted 10 years ago

Hi guys, I'm new here. Just started getting serious about Mathematica yesterday and I'm already getting stumped. What I'm trying to do is import a JSON file from an API of a card game and then make it into a dataset that I can query. At the moment this is the code I have:

apiURL = "https://api.hearthstonejson.com/v1/13921/enUS/cards.json";

hearthJSON = Import[apiURL, "JSON"];

hearthDB = Dataset[hearthJSON];

card001 = hearthDB[[1]]

I get this when I evaluate the last line above. The problem is this output is in a formatted table of some sort inside of Mathematica, it doesn't seem to be an association despite how it pastes on here. Another problem is that Part[] would easier to use if the keys were mapped to the names of the cards instead of an integer.

"type"->"MINION"
"set"->"EXPERT1"
"mechanics"->{"CHARGE"}
"health"->1
"race"->"BEAST"
"name"->"Hound"
"id"->"EX1_538t"
"cost"->1
"text"->"<b>Charge</b>"
"playerClass"->"HUNTER"
"attack"->1

Basically I want to figure out how to do two things:

(*Return cards by using the name of the card*)
hearthDB[["Hound"]]
(*Return a list of cards that share an attribute*)
hearthDB[["HUNTER"]]

I've been digging around the documentation for about six hours now. I think maybe I should be using Lookup[] instead. Anyway, thanks in advance!

POSTED BY: Tyler C
3 Replies
Posted 10 years ago

Thank you so much, you're a godsend

POSTED BY: Tyler C

Wait a minute, here is a way:

ds[Select[#name === "Hound" &]]
ds[Select[#playerClass === "HUNTER" &]]
POSTED BY: Gianluca Gorni

To get a list of associations I would try this way:

ds=Dataset[Association @@@ hearthJSON]

I still have to learn how to interrogate datasets.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard