Home Download Buy Blog Forum Support

How to a serialize ST settings object

How to a serialize ST settings object

Postby ol_ol_3388 on Thu Feb 07, 2013 3:15 am

Hello:

In my plugin I'm getting a Setting object by:
Code: Select all
PLUGIN_SETTINGS = sublime.load_settings(mysettings.sublime-settings')


How can I create a JSON object or a String out of it (-- serialize Setting object) ?

print(json.dump(PLUGIN_SETTINGS.__dict__)) returns {}

Thanks
ol_ol_3388
 
Posts: 18
Joined: Mon Feb 04, 2013 3:29 pm

Re: How to a serialize ST settings object

Postby sapphirehamster on Thu Feb 07, 2013 3:49 am

AFAIK, there is no way to iterate over a settings object to determine which values it contains.

Why are you trying to serialize it? Sublime has the capability to save settings changes for you.
sapphirehamster
 
Posts: 91
Joined: Sun Jul 01, 2012 11:19 pm

Re: How to a serialize ST settings object

Postby ol_ol_3388 on Thu Feb 07, 2013 3:53 am

Thanks for your answer.

I am trying to pass settings object to javascript process running under Node.js
ol_ol_3388
 
Posts: 18
Joined: Mon Feb 04, 2013 3:29 pm

Re: How to a serialize ST settings object

Postby facelessuser on Thu Feb 07, 2013 5:38 am

You can do this. I have done it before. But you have to parse it yourself. That means read the Json file, parse out comments, and then convert the buffer to a json object with the python json module. I don't feel well today (sick), so I don't feel like expounding in any great length on this, but if I feel better tomorrow, I will show how I do it.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: How to a serialize ST settings object

Postby ol_ol_3388 on Thu Feb 07, 2013 2:24 pm

facelessuser wrote:But you have to parse it yourself. That means read the Json file, parse out comments, and then convert the buffer to a json object with the python json module


I was thinking about it, but does it mean that I need to do it separately for default settings and user settings and than merge those two objects into one ?
ol_ol_3388
 
Posts: 18
Joined: Mon Feb 04, 2013 3:29 pm

Re: How to a serialize ST settings object

Postby facelessuser on Thu Feb 07, 2013 4:00 pm

Yes, you would have to merge them, but it would be a shallow merge (just the top level keys; ST doesn't merge deeper than the first level of keys). It is not too difficult a task.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 10 guests