lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

Anyone have a JSON to Lua syntax converter in their tool bag?

Considering how close both syntax are, it should be a breeze:

[JSON]
{
    "firstName": "John",
    "lastName": "Smith",
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": 10021
    },
    "phoneNumbers": [
        "212 732-1234",
        "646 123-4567"
    ]
}

[Lua]
{
    [ "firstName" ] = "John",
    [ "lastName" ] = "Smith",
    [ "address" ] = {
        [ "streetAddress" ] = "21 2nd Street",
        [ "city" ] = "New York",
        [ "state" ] = "NY",
        [ "postalCode" ] = 10021
    },
    [ "phoneNumbers" ] = {
        "212 732-1234",
        "646 123-4567"
    }
}

E.g. wrap the keys with [], change the ':' to '=', the list delimitator to {}, null to nil and that should be pretty much it.

Then run loadstring on it or something.

Thoughts?

Cheers,

PA.