mardi 11 octobre 2022

Random JSON file to DataStruct unmarshalling

I want to create a Data Struct (DS) in GOLANG given a random JSON file. That is, take the JSON file's content and unmarshall it into the DS.

Looking around, I have found solutions on how to create such DS which require knowing beforehand the JSON format (Key:value pairs, types of the values, etc.). To do that, it would be also required to 'manually' enter the fields of the struct, and then unmarshall the JSON content into it. Of course, you can always create a small script that does that. However, that seems a bit unpractical, but not entirely impossible or unimplementable.

Do you know a more straightforward way to achieve this?

I think I also found something about porting the JSON's content into an interface, but I am sure (not 100%, though), that we will want to keep these data in a more static format, i.e. a DS. Is there a way to transform this hypothetical interface to a DS?




Aucun commentaire:

Enregistrer un commentaire