| 1032 | } // namespace |
| 1033 | |
| 1034 | Result<std::shared_ptr<Array>> ArrayFromJSONString(const std::shared_ptr<DataType>& type, |
| 1035 | std::string_view json_string) { |
| 1036 | std::shared_ptr<JSONConverter> converter; |
| 1037 | RETURN_NOT_OK(GetConverter(type, &converter)); |
| 1038 | |
| 1039 | simdjson::padded_string padded_string{json_string}; |
| 1040 | |
| 1041 | sj::parser parser; |
| 1042 | sj::document json_doc; |
| 1043 | auto error = parser.iterate(padded_string).get(json_doc); |
| 1044 | if (error) { |
| 1045 | return Status::Invalid("JSON parse error: ", simdjson::error_message(error)); |
| 1046 | } |
| 1047 | sj::value json_obj; |
| 1048 | if (auto error_code = json_doc.get_value().get(json_obj); |
| 1049 | error_code != simdjson::SUCCESS) { |
| 1050 | return Status::Invalid("JSON parse error: ", simdjson::error_message(error_code)); |
| 1051 | } |
| 1052 | ARROW_ASSIGN_OR_RAISE(auto array, internal::GetJsonAs<sj::array>(json_obj)); |
| 1053 | |
| 1054 | // The JSON document should be an array, append it |
| 1055 | RETURN_NOT_OK(converter->AppendValues(array)); |
| 1056 | // The parser is lazy and does not look past the end of the array by itself |
| 1057 | if (!json_doc.at_end()) { |
| 1058 | return Status::Invalid("JSON parse error: trailing content after JSON array"); |
| 1059 | } |
| 1060 | std::shared_ptr<Array> out; |
| 1061 | RETURN_NOT_OK(converter->Finish(&out)); |
| 1062 | return out; |
| 1063 | } |
| 1064 | |
| 1065 | Result<std::shared_ptr<Array>> ArrayFromJSONString(const std::shared_ptr<DataType>& type, |
| 1066 | const std::string& json_string) { |