| 1032 | } |
| 1033 | |
| 1034 | Result<std::shared_ptr<Scalar>> ScalarFromJSONString( |
| 1035 | const std::shared_ptr<DataType>& type, std::string_view json_string) { |
| 1036 | std::shared_ptr<JSONConverter> converter; |
| 1037 | RETURN_NOT_OK(GetConverter(type, &converter)); |
| 1038 | |
| 1039 | rj::Document json_doc; |
| 1040 | json_doc.Parse<kParseFlags>(json_string.data(), json_string.length()); |
| 1041 | if (json_doc.HasParseError()) { |
| 1042 | return Status::Invalid("JSON parse error at offset ", json_doc.GetErrorOffset(), ": ", |
| 1043 | GetParseError_En(json_doc.GetParseError())); |
| 1044 | } |
| 1045 | |
| 1046 | std::shared_ptr<Array> array; |
| 1047 | RETURN_NOT_OK(converter->AppendValue(json_doc)); |
| 1048 | RETURN_NOT_OK(converter->Finish(&array)); |
| 1049 | DCHECK_EQ(array->length(), 1); |
| 1050 | return array->GetScalar(0); |
| 1051 | } |
| 1052 | |
| 1053 | Result<std::shared_ptr<Scalar>> DictScalarFromJSONString( |
| 1054 | const std::shared_ptr<DataType>& type, std::string_view index_json, |