Javascript data structure validator