ofParameter to ofJson

Hi all!

I would like to know how is the current status of saving ofParameters to JSON
format. Is it already implemented? otherwise, is it in the roadmap?

As far as I can see ofxXML has this serialize() function to stringify all parameters of a ofParameterGroup. But I see that so far ofJson is just a rename of nlohmann::json which obviously does not implement such method.

Any fast advice to get ofParameters save/load to JSON ?

Thanks!

Hi, I haven’t tried this at all, but I saw these JSON related commits on the openframeworks master from Arturo:

https://github.com/openframeworks/openFrameworks/commit/e9456bdb51f983e5aa0475db472f9e0474c4e41c

https://github.com/openframeworks/openFrameworks/commit/ac5c45137bdf517f1d37d7278d7cfa5c91519881

Thank you @hahakid !

I was looking at ofxJsonSettings but I wanted to avoid addons since there are many versions of ofxJSON out there.

I will give it a try :slight_smile:
Thank you again!

yes if you are in master using ofxGui you can just set the file to save to as .json and it’ll use ofJson automatically

Thank you @arturo
And if I’m not using ofxGui? is there any plans to move this feature to ofParameterGroup? or am I asking something stupid ?

you can also do something like:

ofJson json;
ofSerialize(parameterGroup, json);
ofSaveJson("settings.json", json);
```
4 Likes

And the same with ofXml

1 Like

oh great! that’s what I was looking for!
Thank you so much!

hey, I am trying to store easily my app data from a “vector of variables/ofParameters inside an struct” to a json/xml file.
My data is something like this:

struct PRESET_Struct {
		int CURVE_TYPE;
		float ADSR_ATTACK;
		float OUT_frequency;
		bool OUT_TAP;
		bool OUT_ENV;
		bool NOISE_ENABLE;
		int OUT_NOISE_POWER;
		bool OUT_NOISE_TRIGGER;
		bool OUT_BPM_TAP;
		bool LFO_ENABLE;
		bool LFO_STATE;
		int LFO_timeCycle;
	};
	PRESET_Struct myPreset;
	vector <PRESET_Struct> myKit;

I found this two addons based on https://msgpack.org/:
https://github.com/Akira-Hayasaka/ofxMessagePack
https://github.com/hiroyuki/ofxMessagePack

But I can’t make them work yet, and I don’t know if there’s any new OF core method to do this.
I still using 0.9.8 and VS2015