fix npm installed command

#10109
Try to search JSON in whole file, not from first occurrence of '[' or '{'. And fix some logic