// ToJSON writes the DataFrame as JSON.
// This will write newline delimited JSON with each line as a single record.
// This is equivaliant to Pandas to_json when you specify:
// orient='records' and lines=True.
ToJSON writes the DataFrame as JSON.
This will write newline delimited JSON with each line as a single record.
This is equivaliant to Pandas to_json when you specify:
orient='records' and lines=True.
// ToJSON writes the DataFrame as JSON . // This will write newline delimited JSON with each line as a single record . // This is equivaliant to Pandas to_json when you specify : // orient = ' records ' and lines = True .
func (df *DataFrame) ToJSON(w io.Writer) error {
	schema := df.Schema()
	fields := schema.Fields()
	names := make([]string, len(fields))
	for i, field := range fields {
		names[i] = field.Name
	}
	isMap := make([]bool, len(fields))
	for i, field := range fields {
		isMap[i] = metadata.OriginalMapTypeMetadataExists(field.Metadata)
	}
	fmt.Printf("isMap: %v\n", isMap)
	it := iterator.NewStepIteratorForColumns(df.Columns())
	defer it.Release()
	enc := json.NewEncoder(w)
	for it.Next() {
		stepValue, err := it.ValuesJSON()
		if err != nil {
			return err
		}
		jsonObj := make(map[string]interface{})
		for i, jsonValue := range stepValue.ValuesJSON {
			if isMap[i] {
				fmt.Printf("jsonValue: %#v\n", jsonValue)
				obj, ok := mergeKeyValuePairs(jsonValue)
				if !ok {
					fmt.Println("could not merge key value pairs")
					continue
				}
				jsonObj[names[i]] = obj
				continue
			}
			jsonObj[names[i]] = jsonValue
		}
		err = enc.Encode(jsonObj)
		if err != nil {
			return err
		}
	}
	return nil
}
func ( df * DataFrame ) ToJSON ( w io . Writer ) error { schema := df . Schema ( ) fields := schema . Fields ( ) names := make ( [ ] string , len ( fields ) ) for i , field := range fields { names [ i ] = field . Name } isMap := make ( [ ] bool , len ( fields ) ) for i , field := range fields { isMap [ i ] = metadata . OriginalMapTypeMetadataExists ( field . Metadata ) } fmt . Printf ( " \n " , isMap ) it := iterator . NewStepIteratorForColumns ( df . Columns ( ) ) defer it . Release ( ) enc := json . NewEncoder ( w ) for it . Next ( ) { stepValue , err := it . ValuesJSON ( ) if err != nil { return err } jsonObj := make ( map [ string ] interface { } ) for i , jsonValue := range stepValue . ValuesJSON { if isMap [ i ] { fmt . Printf ( " \n " , jsonValue ) obj , ok := mergeKeyValuePairs ( jsonValue ) if ! ok { fmt . Println ( " " ) continue } jsonObj [ names [ i ] ] = obj continue } jsonObj [ names [ i ] ] = jsonValue } err = enc . Encode ( jsonObj ) if err != nil { return err } } return nil }
ToJSON writes the DataFrame as JSON.
ToJSON writes the DataFrame as JSON .
// TODO(nickpoorman): remove this once Map type is supported in Arrow // https://issues.apache.org/jira/browse/ARROW-5640 // Iterate over the rows and extract one row at a time. // At this point everything in stepValue is json. // We just have to build the object from it.