refactor YAML/JSON heuristics into a new load_string method