Sublime Forum

How to a serialize ST settings object

#1

Hello:

In my plugin I’m getting a Setting object by:

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

1 Like

#2

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.

1 Like

#3

Thanks for your answer.

I am trying to pass settings object to javascript process running under Node.js

1 Like

#4

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.

1 Like

#5

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 ?

1 Like

#6

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.

1 Like