DEV Community

Discussion on: #30daysofelm Day 15: Struggling with JSON :|

Collapse
 
wolfadex profile image
Wolfgang Schuster • Edited

Sorry JSON is causing you such troubles. Maybe a few pointers to help guide you towards an answer when you come back to this day, assuming you do.

Some suggestions on changes to your types. Looking at your data

{
  "Jupiter": {
    "lightMinutes": 49.561547588282494,
    "xyz": [
      -15.160997437594864,
      35.36776769042324,
      86.01557267383876
    ]
  },
 ...
}
Enter fullscreen mode Exit fullscreen mode

To me, this looks more like Dict String PlanetInfo since you're only going to have 1 instance for each planet. List Planet would allow multiples of any planet.

Next, your PlanetInfo looks close, but I think you'd be better suited to have the "xyz" key converted to something like

type alias Point =
    { x : Float
    , y : Float
    , z : Float
    }
Enter fullscreen mode Exit fullscreen mode

This brings your types to something like

type alias Planets =
    Dict String PlanetInfo

type alias PlanetInfo =
    { lightMinutes : Float
    , position : Point
    }

type alias Point =
    { x : Float
    , y : Float
    , z : Float
    }
Enter fullscreen mode Exit fullscreen mode

I hope this gives you a much better starting point. Happy to help more if you're interested.


And happy new year!

Collapse
 
kristianpedersen profile image
Kristian Pedersen

Thank you so much, and happy new year!

I had overlooked dicts, and there are a couple of other things I'm not clear on, so elm/core is on today's reading list. :D

Your input seems like a very good starting point for today. Yesterday was still a step forward, so I'm happy with my progress. Again, thanks for your help!