danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

Unexpected Read Behavior on list of JSON

Open kohehir opened this issue 4 years ago • 6 comments

Describe the bug When creating a DataFrame from a list of JSON objects with key value pair data, the DataFrame ignores keys and populates the DataFrame using the order of the values passed. Below is a toy example of this behavior.

To Reproduce

json_data = [{ A: "A", B: "B", C: "C"},
             { A: "A", B: "B", C: "C"},
             { C: "C", B: "B", A: "A" },
             {A: "A", C: "C"}]

df = new dfd.DataFrame(json_data)
table(df)

This generates the below table.

image

Expected behavior More logical output would be the below:

image

kohehir avatar Oct 24 '21 23:10 kohehir

@kohehir Reading JSON into DataFrames does not use the object key, we instead use the position. Going forward, we may add an option to use keyed objects.

risenW avatar Nov 07 '21 12:11 risenW

Unfortunately, this makes usage with JSON almost pointless. JSON by definition is not required to be ordered. From the source JSON.org An object is an unordered set of name/value pairs.

skwasha avatar Dec 16 '21 10:12 skwasha

Unfortunately, this makes usage with JSON almost pointless. JSON by definition is not required to be ordered. From the source JSON.org An object is an unordered set of name/value pairs.

I’ve come to realize this as well. I’ve added it as a priority to the next update.

risenW avatar Dec 16 '21 12:12 risenW

@skwasha This issue is still happening on the toJSON function, was there a specific configuration for the toJSON call?

mazenashgar avatar Jan 01 '23 18:01 mazenashgar

@skwasha This issue is still happening on the toJSON function, was there a specific configuration for the toJSON call?

I think perhaps you meant to mention someone else?

skwasha avatar Jan 04 '23 23:01 skwasha

My apologies @skwasha I meant to mention @risenW

mazenashgar avatar Jan 04 '23 23:01 mazenashgar