HISE Logo Forum
    • Categories
    • Register
    • Login

    Deleting .json Items || = undefined??

    Scheduled Pinned Locked Moved Scripting
    5 Posts 2 Posters 48 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.
    • ChazroxC
      Chazrox
      last edited by Chazrox

      How do we delete an item from .json? My 'Rename Preset' isnt replacing the selected preset for some reason, its adding a new item. Im removing the item before writing the object back to file so im assuming the deleting isnt happening.

      		//-------Delete the Old Entry---------------------------		
      		AttackTablePresets[oldName] = undefined;
      

      This is the full 'Rename' button script as of now...

      // -------------------------RENAME PRESET BUTTON CONTROLS-----------------------		
      	inline function onRenamePresetButtonControl(component, value)
      	{
      		if (!value)
      			return;
      		//-------------------------------------------------------------------			
      		local oldName = PresetList.getItemText(); // Name in combobox
      		local newName = PresetNameToSave.get("text").trim(); // Name in text field
      
      		//-------------------------------------------------------------------
      		if (newName == "" || newName == oldName)
      			return;
      
      		//-------------------------------------------------------------------		
      		// If new name already exists, do nothing or show warning. 
      		if (isDefined(AttackTablePresets[newName]))
      		{
      			Console.print("A preset with that name already exists.");
      			return;
      		}
      
      		//-------------------------------------------------------------------	
      		// Duplicate Data
      		AttackTablePresets[newName] = AttackTablePresets[oldName]; // Copy data FROM oldName TO newName
      
      		//-------------------------------------------------------------------		
      		// Rebuild the object without the old key
      		local newPresets = {}; // Clear the array
      		for (k in AttackTablePresets)
      		{
      			if (k != oldName)
      				newPresets[k] = AttackTablePresets[k]; // Array, newPresets now without oldName
      		}
      
      		//-------------------------------------------------------------------
      		AttackTablePresets = newPresets.clone(); // Hand back to main array AttackTablePresets		
      
      		//-------------------------------------------------------------------	
      		// Get current values	
      		local tableData0 = TableEnvelope1Pro.exportAsBase64(0); // ATTACK TABLE
      		local attackKnob = knbAttack.getValue(); // ATTACK TIME KNOB
      
      		AttackTablePresets[newName] = [
      			TableEnvelope1Pro.exportAsBase64(0),
      			knbAttack.getValue()
      		];				
      
      		//-------Delete the Old Entry---------------------------		
      		AttackTablePresets[oldName] = undefined;	
      		//-------------------------------------------------------------------		
      		// Write object to file
      		presetFile1.writeObject(AttackTablePresets);
      		//-------------------------------------------------------			
      		// Update ComboBox
      		local keyList = [];
      
      		for (k in AttackTablePresets)
      			keyList.push(k);		
      		//-------------------------------------------------------------------
      		// Repopulate combobox items and set new value
      		PresetList.set("items", keyList.join("\n"));
      		PresetList.setValue(keyList.indexOf(newName) +1);
      		//-------------------------------------------------------------------		
      		PresetNameToSave.set("text", "");
      	};
      	RenamePresetButton.setControlCallback(onRenamePresetButtonControl);
      

      .json in xcode after trying to rename "1" to "11"
      Screenshot 2025-07-15 at 3.31.54 AM.png

      then my preset combobox has some rogue values. The .json doesnt show those values so idk.
      Screenshot 2025-07-15 at 3.46.53 AM.png

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

        The usual way is to set it to undefined, however very recently the topic came up and Christoph mentioned adding a proper remove function. I'm not sure if it was implemented though.

        Link Preview Image
        How can I efficiently remove a key from an object?

        @d-healey yeah something like JSON.delete(obj, key) is the easiest way, the delete syntax would require a real brain-twister with the current parser.

        favicon

        Forum (forum.hise.audio)

        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 darn, so even if he did it would require me to update which Im afraid to do. Any other suggestions?

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

            @Chazrox said in Deleting .json Items || = undefined??:

            Any other suggestions?

            In that same thread there's an example function for removing an item from an object by rebuilding the object.

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

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

              @d-healey If its writing the new data, and not deleting the old one...where are these numbers coming from?

              d888f7f6-a101-4c0f-b840-a849d08ade97-image.png

              they look like items i've added and removed before but if they arent showing up in the .json file, where are they?

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

              26

              Online

              1.8k

              Users

              12.1k

              Topics

              105.7k

              Posts