Just a first point about nomenclature: what you get when you import a JSON file is not a Mathematica Association
: it is a nested list of Rule
s. Association
(http://reference.wolfram.com/language/ref/Association.html) in Mathematica is a very specific data construct that encapsulates key-value pairs. And even though the list of rules returned from the JSON import is generally a nested list of rules in key-value form--it is not an Association in the Mathematica meaning of the Association function.
That said... each particular analysis that you want to do will involve writing a specific function to grab the data you desire from this list of rules. In some cases it may use the Cases
function, but more generally it will involve using things like Part
and ReplaceAll
.
So here is an example (if you could post a truncated example of one of your JSON data files I could show a couple of examples from that.
But here is a couple of examples. Attached is a JSON file (a very simple one) that I found on the web. If I Import
it I get:
In[1]:= jsonImport = Import["/Users/dreiss/Desktop/json.json"]
Out[1]= {"sex" -> "M", "first" -> "John",
"favorites" -> {"color" -> "Blue", "sport" -> "Soccer",
"food" -> "Spaghetti"}, "last" -> "Doe",
"interests" -> {"Reading", "Mountain Biking", "Hacking"},
"age" -> 39, "salary" -> 70000, "registered" -> True,
"skills" -> {{"tests" -> {{"name" -> "One",
"score" -> 90}, {"name" -> "Two", "score" -> 96}},
"category" ->
"JavaScript"}, {"tests" -> {{"name" -> "One",
"score" -> 79}, {"name" -> "Two", "score" -> 84}},
"category" ->
"CouchDB"}, {"tests" -> {{"name" -> "One",
"score" -> 97}, {"name" -> "Two", "score" -> 93}},
"category" -> "Node.js"}}}
So lets find the "skills" data:
In[3]:= "skills" /. jsonImport
Out[3]= {{"tests" -> {{"name" -> "One",
"score" -> 90}, {"name" -> "Two", "score" -> 96}},
"category" ->
"JavaScript"}, {"tests" -> {{"name" -> "One",
"score" -> 79}, {"name" -> "Two", "score" -> 84}},
"category" ->
"CouchDB"}, {"tests" -> {{"name" -> "One",
"score" -> 97}, {"name" -> "Two", "score" -> 93}},
"category" -> "Node.js"}}
And, instead of this let's see the "tests" directly:
In[3]:= testData = "tests" /. ("skills" /. jsonImport)
Out[3]= {{{"name" -> "One", "score" -> 90}, {"name" -> "Two",
"score" -> 96}}, {{"name" -> "One",
"score" -> 79}, {"name" -> "Two",
"score" -> 84}}, {{"name" -> "One",
"score" -> 97}, {"name" -> "Two", "score" -> 93}}}
And, now knowing this structure we can get the values for the test with "name" that has the value "one":
In[5]:= Cases[testData, ({"name" -> "One", "score" -> value_}) :>
value, \[Infinity]]
Out[5]= {90, 79, 97}
And this result can be analyzed and visualized...