function main(state) {
    try {
        const input = state.text
        const unserialized = unserialize(input)
        const data = unserialized[0]

        if(unserialized[1] != input.length) {
            throw new Error("Invalid serialized string")
        }

        if(data === null || data === undefined) {
            state.text = null
        } else if(typeof data === 'object') {
            state.text = JSON.stringify(data, null, 2)
        } else {
            state.text = data.toString()
        }
    } catch (e) {
        state.postError(e.message)
    }
}
{
    "api":1,
    "name":"PHP Unserialize",
    "description":"Convert PHP serialized data to JSON",
    "author":"Rob Bogie",
    "icon":"elephant",
    "tags":"php,serialize,unserialize,json"
  }