saveAsJSON



  • Theres a LoadAsJSON - which I'm hoping returns a file as a string that I can interrogate, it would be nice to have saveAsJSON too. Then we could have a persistant storage mechanism outside of User Presets

    saveAsJSON(,<string>,<filepath and name>)



  • LoadAsJSON is almost as old as HISE, so I have no idea what I have implemented back then 🙂

    But this suggestion makes sense. I'd like to limit the file accessibility to the project's app data folder though (the location where all the setting files are stores), otherwise you end up parsing a string wrong and overwrite your root directory...



  • @Christoph-Hart yep all makes sense, in fact I think it would be ok to offer an even simpler structure, say comma delimited string instead of JSON, as JSON would require a little bit of structuring which might be overhead if all you want to save is "12345".

    The way Kontakt does it is it allows you to load/save an array - which might be a nice convenient middle ground of structure vs safety.

    Your call of course.



  • If you just need an array, do something like this:

    {
    "Data": ["1234", "5678"]
    }
    

    JSON is the way to go, everything else is hacky and just an temporary solution.



  • @Christoph-Hart yeah fine, but how do I save and read an array to disk?



  • Wait a moment. The function already works as it should be 🙂

    // That's the object we're about to store
    var d = 
    {
        "Data": ["1234", "5678"]
    };
    
    // You can either supply a relative path or an absolute path
    // The relative path uses the user preset directory as root
    // so if you want to dump it in the app data folder, just go
    // up one directory level (in HISE it will place the file in
    // the project root folder.
    Engine.dumpAsJSON(d, "../testFunk.js");
    
    var d2 = Engine.loadFromJSON("../testFunk.js");
    
    // Magic trick using an temporary file...
    Console.print(d2.Data[0]);
    


  • Aah, I have to change it to not throw an error if the file doesn't exist, but just return an empty var instead - speaking of return values 🙂



  • @Christoph-Hart really, I'm at the point of taking any (even slightly ragged) functionality... so thanks


Log in to reply
 

7
Online

491
Users

1.7k
Topics

12.9k
Posts