Flatty

Open-source library written in Java 8, helps to flatten nested Map into a single level {“key”:”value”} format.

https://github.com/skirdey/flatty

As an example, it could flatten an Map object that looks like this:

{
    "key": {
        "col": [
            1,
            2,
            {},
            {
                "a": "b",
                "c": [
                    null,
                    1,
                    "string",
                    true
                ]
            },
            []
        ]
    }
}

to

{
    "key__col[0]": 1,
    "key__col[1]": 2,
    "key__col[2]": {},
    "key__col[3]__a": "b",
    "key__col[3]__c[0]": null,
    "key__col[3]__c[1]": 1,
    "key__col[3]__c[2]": "string",
    "key__col[3]__c[3]": true,
    "key__col[4]": []
}

and unflatten it back.

Leave a Reply

Your email address will not be published. Required fields are marked *