malcontent icon indicating copy to clipboard operation
malcontent copied to clipboard

Avoid using map collections in the json output

Open hectorj2f opened this issue 1 year ago • 1 comments

Map collections are not part of the JSON standard compliant. It'd be great to change the json output to use json objects instead of map collections.

hectorj2f avatar May 10 '24 10:05 hectorj2f

TIL that Go's JSON encoder is able to generate non-compliant JSON :(

tstromberg avatar May 10 '24 17:05 tstromberg

Wouldn't it be possible for us to change the FileReport struct to use an array of Behavior instead of a map[string]Behavior ? I am trying to use the JSON output to store it in BigQuery. But the map collection isn't supported so I have to convert/iterate over all the bincapz results :/.

hectorj2f avatar May 13 '24 14:05 hectorj2f

Map collections are not part of the JSON standard compliant. It'd be great to change the json output to use json objects instead of map collections.

Can you explain this? I don't believe you.

jonjohnsonjr avatar May 13 '24 20:05 jonjohnsonjr

Although map-like structures can be represented using JSON, because they don't require a schema. Applications can use a "schema-on-read" approach, where the application ingests the data and then queries based on assumptions about a schema. Regarding map-like structures, the JSON schema doesn't explicitly recommend or provide built-in support for them, that is why is sometimes recommended to construct instead JSON objects that reassemble like map collections. By following this, you sometimes avoid flattening the JSON structure out when they are represented as map collections.

When I referred to JSON compliant I meant that certain processing services sometimes have limitations when it comes to handle complex structures (map collections or dynamic schemas) in JSON.

hectorj2f avatar May 13 '24 22:05 hectorj2f

Wouldn't it be possible for us to change the FileReport struct to use an array of Behavior instead of a map[string]Behavior ?

Sure - I'm open to that. PR's welcome!

tstromberg avatar May 14 '24 12:05 tstromberg