HISE Logo Forum
    • Categories
    • Register
    • Login

    Read & Write JSON file || Basics

    Scheduled Pinned Locked Moved Solved Scripting
    31 Posts 3 Posters 332 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.
    • d.healeyD
      d.healey @Chazrox
      last edited by d.healey

      @Chazrox

      // Create an object
      const myObj = {"name": "Dave", "age": 38, "country": "England"};
      
      // Save object to a file on desktop
      inline function saveObject(obj)
      {
          local f = FileSystem.getFolder(FileSystem.Desktop).getChildFile("myFile.json"); 
          f.writeObject(obj);
      }
      
      // Load the file 
      inline function loadObject()
      {
          local f = FileSystem.getFolder(FileSystem.Desktop).getChildFile("myFile.json"); 
          
          if (!f.isFile())
              return {}; // Invalid file, return empty object
      
          return f.loadAsObject(); // What you will have here is the same as the object you started with
      }
      
      

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      ChazroxC 2 Replies Last reply Reply Quote 1
      • ChazroxC
        Chazrox @d.healey
        last edited by

        @d-healey Thank you!

        check my edit just in case. 🙏

        1 Reply Last reply Reply Quote 0
        • ChazroxC
          Chazrox @d.healey
          last edited by

          @d-healey Im writing to a .json file and saving into UserPresets root folder. Is that all good?

          d.healeyD 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey @Chazrox
            last edited by

            @Chazrox said in Read & Write JSON file || Basics:

            UserPresets root folder. Is that all good?

            You should only put user presets in there. If you want to save to a fixed location use the app data folder. https://docs.hise.dev/scripting/scripting-api/filesystem/index.html

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            ChazroxC 1 Reply Last reply Reply Quote 0
            • ChazroxC
              Chazrox @d.healey
              last edited by

              @d-healey I was trying that one and I couldnt find where the file was going to.

              Is AppData a folder within the plugin or is that a system folder?

              d.healeyD 1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey @Chazrox
                last edited by d.healey

                @Chazrox said in Read & Write JSON file || Basics:

                Is AppData a folder within the plugin or is that a system folder?

                It's a system folder - it's where the UserPresets folder lives, among other things.

                • GNU/Linux: /home/username/.config/Company Name/Plugin Name/
                • Windows: Users/username/AppData/Roaming/Company Name/Plugin Name/
                • MacOS:~/Library/Application Support/Company Name/Plugin Name/

                You can open it from the File menu in HISE btw.

                d162d44a-32e8-4263-bfa5-66ece8617000-image.png

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

                ChazroxC 1 Reply Last reply Reply Quote 1
                • ChazroxC
                  Chazrox @d.healey
                  last edited by

                  @d-healey got it. 🙏

                  So I got that much working, the part im missing is....

                  How do I add new pairs to the object after its created?

                  1 Reply Last reply Reply Quote 0
                  • ChazroxC
                    Chazrox
                    last edited by

                    wait dont give me the answer yet....im getting it. lol.

                    LindonL 1 Reply Last reply Reply Quote 1
                    • LindonL
                      Lindon @Chazrox
                      last edited by

                      @Chazrox said in Read & Write JSON file || Basics:

                      wait dont give me the answer yet....im getting it. lol.

                      hint - arrays are json "objects" too

                      HISE Development for hire.
                      www.channelrobot.com

                      ChazroxC 1 Reply Last reply Reply Quote 1
                      • ChazroxC
                        Chazrox @Lindon
                        last edited by

                        @Lindon

                        via GIPHY

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

                          @Chazrox

                          // create an array for objects
                          const var myObjectSet = [];
                          // Create an object
                          const myObj = {"name": "Dave", "age": 38, "country": "England"};
                          myObjectSet.push(myObj);
                          
                          const myObj2 = {"name": "Lindon", "age": 150, "country": "England"};
                          myObjectSet.push(myObj2);
                          
                          Console.print(trace(myObjectSet));
                          

                          HISE Development for hire.
                          www.channelrobot.com

                          ChazroxC 1 Reply Last reply Reply Quote 1
                          • ChazroxC
                            Chazrox @Lindon
                            last edited by Chazrox

                            @Lindon nice! That was it! I get it now.

                            I just recently got comfortable sorting, cloning, flipping arrays so if this is anything like that im off to a good start.

                            Screenshot 2025-07-09 at 4.12.25 AM.png
                            Huge breakthrough for me here. haha.

                            Thank You @d-healey & @Lindon !

                            @Lindon said in Read & Write JSON file || Basics:

                            hint - arrays are json "objects" too

                            So are all array api's available for these too?

                            LindonL 1 Reply Last reply Reply Quote 0
                            • ChazroxC Chazrox marked this topic as a question
                            • ChazroxC Chazrox has marked this topic as solved
                            • LindonL
                              Lindon @Chazrox
                              last edited by

                              @Chazrox said in Read & Write JSON file || Basics:

                              So are all array api's available for these too?

                              Arrays are just arrays - so yes the array API is applicable to them...but your array elements are "complex" objects so heaven knows how stuff like sort would work - if at all....

                              HISE Development for hire.
                              www.channelrobot.com

                              ChazroxC d.healeyD 2 Replies Last reply Reply Quote 1
                              • ChazroxC
                                Chazrox @Lindon
                                last edited by

                                @Lindon Ok. I'll do some reading on that too.

                                @Lindon said in Read & Write JSON file || Basics:

                                heaven knows...

                                😆

                                1 Reply Last reply Reply Quote 0
                                • d.healeyD
                                  d.healey @Lindon
                                  last edited by

                                  @Lindon said in Read & Write JSON file || Basics:

                                  but your array elements are "complex" objects so heaven knows how stuff like sort would work - if at all....

                                  Custom sort function

                                  Libre Wave - Freedom respecting instruments and effects
                                  My Patreon - HISE tutorials
                                  YouTube Channel - Public HISE tutorials

                                  ChazroxC 1 Reply Last reply Reply Quote 0
                                  • ChazroxC
                                    Chazrox @d.healey
                                    last edited by Chazrox

                                    @d-healey

                                    can you take a look at this please?
                                    // Im trying to add 'newPreset' to 'AttackTablePresets'

                                    
                                    const var AttackTablePresets = 
                                    {
                                    		
                                    	"name": "36...............vOLVxe+....9izwDzO...f+....9C...vO", 
                                    	"name2": "36...............vOLVxe+....9izwDzO...f+....9C...vO", 
                                    	"name3": "36...............vOLVxe+....9izwDzO...f+....9C...vO"
                                    		
                                    };
                                    
                                    // SAVE PRESET BUTTON CONTROLS
                                    inline function onSaveOkControl(component, value)
                                    {	
                                    
                                    	
                                    	if (value)
                                    	{
                                    		local tableData0 = TableEnvelope1Pro.exportAsBase64(0);		
                                    		local newPreset = {Newshit : tableData0};
                                    		
                                    		AttackTablePresets.insert(newPreset); 
                                    
                                    // Im trying to add 'newPreset' to 'AttackTablePresets'
                                    		
                                    		Console.print("START TRACE" + trace(myObjectSet) + "END TRACE");
                                    	}
                                    };
                                    Content.getComponent("SaveOk").setControlCallback(onSaveOkControl);
                                    
                                    d.healeyD 1 Reply Last reply Reply Quote 0
                                    • d.healeyD
                                      d.healey @Chazrox
                                      last edited by d.healey

                                      @Chazrox

                                      const myObj = {"name": "Dave", "age": 38, "country": "England"};
                                      
                                      // To add something new you can use dot notation
                                      myObj.newKey = newValue;
                                      
                                      // Or you can use bracket notation - only really needed if you have spaces in the key or are using a variable to hold the key
                                      myObj["newKey"] = newValue;
                                      

                                      @Chazrox said in Read & Write JSON file || Basics:

                                      AttackTablePresets.insert(newPreset);

                                      This is for arrays, not objects. I think Lindon confused you :)

                                      Libre Wave - Freedom respecting instruments and effects
                                      My Patreon - HISE tutorials
                                      YouTube Channel - Public HISE tutorials

                                      ChazroxC 1 Reply Last reply Reply Quote 0
                                      • ChazroxC
                                        Chazrox @d.healey
                                        last edited by

                                        @d-healey oh wow..how do I find the rest of the dot.functions?

                                        d.healeyD 1 Reply Last reply Reply Quote 0
                                        • d.healeyD
                                          d.healey @Chazrox
                                          last edited by

                                          @Chazrox It's not a function, it's accessing the property of the object.

                                          Just like when you use .length to find out how many characters are in a string or elements in an array. If it doesn't have () at the end then it's not a function.

                                          You're going to love my scripting course :)

                                          Libre Wave - Freedom respecting instruments and effects
                                          My Patreon - HISE tutorials
                                          YouTube Channel - Public HISE tutorials

                                          ChazroxC 2 Replies Last reply Reply Quote 0
                                          • ChazroxC
                                            Chazrox @d.healey
                                            last edited by

                                            @d-healey

                                            @d-healey said in Read & Write JSON file || Basics:

                                            You're going to love my scripting course :)

                                            I cant wait! Im there!

                                            When I say I watch all of your videos...

                                            I mean it. lol. (muuuultiple times and still learning always)
                                            Screenshot 2025-07-09 at 5.16.17 AM.png

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

                                            19

                                            Online

                                            1.8k

                                            Users

                                            12.1k

                                            Topics

                                            105.3k

                                            Posts