AlwaysZhi commented on issue #37647:
URL: https://github.com/apache/arrow/issues/37647#issuecomment-1720500455
Now i convert the json format and use **WithMultipleDocs** option, it works
well.
```go
func TestReadJson(t *testing.T) {
file, err := os.Open("/home/data/180000.json")
if err != nil {
fmt.Println("open json:", err)
}
defer file.Close()
content, err := io.ReadAll(file)
if err != nil {
fmt.Println("read file:", err)
}
var jsonData []map[string]interface{}
err = json.Unmarshal(content, &jsonData)
if err != nil {
fmt.Println("Unmarshal failed:", err)
}
schema := arrow.NewSchema([]arrow.Field{
{Name: "instruction", Type: arrow.BinaryTypes.String, Nullable:
true},
{Name: "input", Type: arrow.BinaryTypes.String, Nullable: true},
{Name: "output", Type: arrow.BinaryTypes.String, Nullable:
true},
}, nil)
mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
var recs []arrow.Record
for _, obj := range jsonData {
bytes, err := json.Marshal(obj)
if err != nil {
fmt.Println("Marshal failed:", err)
}
rec, _, err := array.RecordFromJSON(mem, schema,
strings.NewReader(string(bytes)), array.WithMultipleDocs())
recs = append(recs, rec)
}
fmt.Println("value -", recs[0].Column(0))
fmt.Println("value -", recs[0].Column(1))
fmt.Println("value -", recs[0].Column(2))
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]