HISE Logo Forum
    • Categories
    • Register
    • Login

    saveAsJSON

    Scheduled Pinned Locked Moved Feature Requests
    8 Posts 2 Posters 730 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • LindonL
      Lindon
      last edited by

      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(,,)

      HISE Development for hire.
      www.channelrobot.com

      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart
        last edited by

        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...

        LindonL 1 Reply Last reply Reply Quote 0
        • LindonL
          Lindon @Christoph Hart
          last edited by

          @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.

          HISE Development for hire.
          www.channelrobot.com

          1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart
            last edited by

            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.

            LindonL 1 Reply Last reply Reply Quote 2
            • LindonL
              Lindon @Christoph Hart
              last edited by Lindon

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

              HISE Development for hire.
              www.channelrobot.com

              1 Reply Last reply Reply Quote 0
              • Christoph HartC
                Christoph Hart
                last edited by

                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]);
                
                1 Reply Last reply Reply Quote 1
                • Christoph HartC
                  Christoph Hart
                  last edited by

                  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 :)

                  LindonL 1 Reply Last reply Reply Quote 0
                  • LindonL
                    Lindon @Christoph Hart
                    last edited by

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

                    HISE Development for hire.
                    www.channelrobot.com

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post

                    55

                    Online

                    1.7k

                    Users

                    11.7k

                    Topics

                    101.9k

                    Posts