npm / ini

An ini parser/serializer in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Top-level arrays to not round trip

adamvoss opened this issue · comments

Given the following object as x:

[
    {
        "id": 2,
        "name": "An ice sculpture",
        "price": 12.50,
        "tags": ["cold", "ice"],
        "dimensions": {
            "length": 7.0,
            "width": 12.0,
            "height": 9.5
        },
        "warehouseLocation": {
            "latitude": -78.75,
            "longitude": 20.4
        }
    },
    {
        "id": 3,
        "name": "A blue mouse",
        "price": 25.50,
        "dimensions": {
            "length": 3.1,
            "width": 1.0,
            "height": 1.0
        },
        "warehouseLocation": {
            "latitude": 54.4,
            "longitude": -32.7
        }
    }
]

The following fails:

for (let y of ini.decode(ini.encode(x))) { console.log(y) }

despite the fact the following works:

for (let y of x) { console.log(y) }

The issue being that decoding results in an object where what was an array index is now a key, rather than create an array.

If this can be fixed, great. If it cannot because of backwards compatibility concerns, it would be nice if ini emitted a warning when encoding something that would not decode to an equivalent object.