Alex McMillan
Alex McMillan

Reputation: 17952

Immutablejs: How to deserialise a complex JS object

If I receive data from a server in plain JSON that looks like this:

{
    "f223dc3c-946f-4da3-8e77-e8c1fe4d241b": {
        "name": "Dave",
        "age": 16,
        "jobs": [{
            "description": "Sweep the floor",
            "difficulty": 4
        },{
            "description": "Iron the washing",
            "difficulty": 6
        }]
    },
    "84af889a-8fc9-499b-a6ea-97e7a483130c": {
        ...
    }
}

Do I need to loop through all the jobs and convert them to Maps, then convert each object's jobs into a List, then the entire thing into a Map?

Or does ImmutableJS do this all recursively for me?

Upvotes: 0

Views: 69

Answers (1)

zerkms
zerkms

Reputation: 254906

There is Immutable.fromJS() designed for exactly that.

Upvotes: 1

Related Questions