I work with JSON at the time and save some data. Since I could save a lot space by replacing often used strings I wonder if there is any algorithm out there which can do this. I prefer Javascript since I do it with JavaScript and NodeWebkit, but it would good to know if something like this exists. Because I do this with NodeWebkit the data is stored to the clients computer, so I have no server to communicate with. Additionally, it must be a standalone application, so I should not use external programs.
I imagine to get from this:
{
    "Attribute1" : "This is my very long string",
    "Attribute2" : "This is my very long string",
    "Attribute3" : {
         "innerObjectAttribute": "This string contains the word Attribute"
     }
}
Object something like:
{
    "$$1" : "Attribute",
    "$$2" : "This is my very long string",
    "data": {
           "$$11" : "$$2",
           "$$12" : "$$2",
           "$$13" : {
                 "innerObject$$1" : "This string contains the word $$1"
            }  
     } 
}
Already in this example the algorithm would save space (without spaces), but imagine a case where you use a long word - or a part of a path (which I do) multiple times - in my case it could save a lot (!!) space.
My old JSON-Object were just saved under the data attribute, all strings which were replaced come before that and have his own attribute - but only being once in the whole JSON-file.
Problem with Strings like $$1 when they are used by the user should be considered by the algorithm itself.
I imagine to get my input JSON-string back with a parse/undo function. Does anyone can help here?
 
    