Hi all,
I have a moderately complicated JSON object. A sample looks like:
```
{
"118_192": {
"Cloverdale P": {
"sum_lane_miles": 0,
"sum_single_unit_mt": 0,
"sum_vmt": 57,
"sum_combination_mt": 0
}
}
}
```
Thousands of such top level entries, with a variable number of secondary
entries, and two different types of tertiary entries depending on the
"type" of the second entry. I'm debating between a simple nested dict
approach, and a more complicated nested dict of two alternative object
types, but I can't get past Go with the repl in order to test out my ideas.
First, the most simple case, I can decode this with nested Dictionaries
What I did in the repl is:
```
import Json.Decode as Json exposing (..)
import Dict exposing (..)
inputString = """{ "118_192": { "Cloverdale P": {
"sum_lane_miles": 0, "sum_single_unit_mt": 0, "sum_vmt": 57,
"sum_combination_mt": 0 }, "CO P": { "sum_lane_miles": 0,
"sum_single_unit_mt": 0, "sum_vmt": 43, "sum_combination_mt":
0 } }}"""
gridVolumes = dict ( dict (dict float))
dataDict = decodeString gridVolumes inputString
```
But that last line is a wild guess. What I want to do is get "something" I
can use as a dictionary, but Elm is giving me two things...a Result object
and the dictionary.
```
> dataDict
Ok (Dict.fromList [("118_192",Dict.fromList [("CO P",Dict.fromList
[("sum_combination_mt",0),("sum_lane_miles",0),("sum_single_unit_mt",0),("sum_vmt",43)]),("Cloverdale
P",Dict.fromList
[("sum_combination_mt",0),("sum_lane_miles",0),("sum_single_unit_mt",0),("sum_vmt",57)])])])
: Result.Result
String
(Dict.Dict String (Dict.Dict String (Dict.Dict String Float)))
>
```
How do I strip off the "Result" in the repl so I can touch the dictionary
and play with various types of Dict.get commands?
Obvious to me that I'm just not getting a fundamental concept of the
language, but I can't find the right point of view so far in the docs I've
read...for example, the JSON help page
(https://guide.elm-lang.org/interop/json.html) never actually seems to
*assign* the result of running a JSON parser to a value, and the JSON
library documentation has fragements of code, but no complete worked
examples one can reproduce in the repl.
Any advice or pointers to docs I should read or reread would be
appreciated. Or just a simple "you're doing X wrong do Y instead to get
access to the Dict String (Dict String (Dict String Float))) thing" would
be welcome too!
Regards,
James
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.