netjson: clear allocated memory before setting fields in it