I think that reading a JSON file (made by other FluCoMa objects) from disk into a dictionary and then loading that dictionary should be equivalent to calling .read directly on the object.
intuition wonāt help here. The best bet is to import d, save it, and try to load it back via your own file parsing (I donāt know why you would do that but Iām sure there is a use case).
I see a difference between d and ~jsonB in this code but I might be wrongā¦ double-quote in the ādataā to ādataā - if I find a minute I will try to do what I said above.
It is strange. I get with my last code a valid format yet Iām told it isnāt. I donāt see a native way to save the dict so I can compare it, there must be a comma, or something stupid, added with parseYAML. In Max we had to mess up so much for stuff to behave and in SC it worksā¦ actually I should just read the load code wait a second
ok Iāll need to investigate a bit more with a proper brain on. This is surreal because in this code d and ~jsonB are exactly the sameā¦
Maybe @groma can have a look as it is his code under the hood but I really cannot see the difference between the 2 dicts (they are super small here so I can see them all in the post window!)
Ultimately, if you load a JSON file written by a FluidDatasSet then you should be able to either load it directly or put it into a dict (optionally edit it) and then make the dataset load that.
From what I can tell by testing in Max, you donāt need the idās key of the dictionary. That is the old school format IIRC.
found it. they look the same but they are not the same. check this:
~jsonB[ādataā][0.asString]
vs
d[ādataā][0.asString]
vs
d[ādataā][0]
but still I donāt get it
PS this was written before I read the clever answer of sam, hence the still pending question, but the casting of labels is still funny to read so Iāll leave it here - it also shows Iām slow
I was there with you, I just cast the wrong bit! Thanks for solving this! So @jamesbradbury there is no bug, just a casting issue of loading a string as an array of float. You can cast it as @spluta does here.
I still donāt know why, but maybe you might want to save all your preset in one gigantic meta dict that you parse and load in various objects. so donāt forget to cast your stringād arrays of floats.
Another thing that I discovered in my post just before Samās solution is that the labels seem to be quite permissive (my generating code was not casting them as string) so @groma must have put some stringnification under the hood
Iāve been hassling with string vs. float thing also. itās tricky because for a JSONFileReader to be truly agnostic, it wonāt know if you want that info as a string or as a float. For universality, my vote would be to keep things as strings and let the user cast to float when they need to.
But a, perhaps, more important point:
Maybe this is obvious, but for the names of things (such as dictionary keys), it seems like it would be best to just go without the āsymbolsā, since strings are a more universal type, so more cross-platform friendly (I think currently the FluidFolderLoader stores keys as symbols).
That way whether one loads a āLoaderā index from file (keys will be strings!) or makes it in the moment, they keys will all be strings!
Iām a bit behind here as the discussion went deeper into the SC side of things but I disagree that every thing should be a string which is then cast by the user. The JSON loader should be specced such that you can read the data back in and it will parse to the JSON Object that it was in memory. Correct me if Iāve lost track of the thread here.
If itās loading into a Flucoma object, then yes, it should load it as it was saved.
There was also talk of a generic json loader, for which I wouldnāt want it assuming my ā0ā is a float, it might be an ID. Does JSON protocol have a clever way of specifying type? Kind of like how OSC specifies?