check if string is valid before trying to parse it as JSON