HISE Logo Forum
    • Categories
    • Register
    • Login

    Loading functions stored in an array from a JSON file is coming up "undefined"

    Scheduled Pinned Locked Moved Scripting
    5 Posts 2 Posters 211 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.
    • VirtualVirginV
      VirtualVirgin
      last edited by

      I made a JSON file with info that I need to use in a data table.
      I am storing sort functions in an array inside the JSON.
      The sort functions can be seen in the JSON itself:
      Screenshot 2025-04-14 at 2.58.57 PM.png

      When I load the JSON, all of my other data that was stored in the file will load properly,
      but the sort functions just come up as "undefined":

      Screenshot 2025-04-14 at 2.59.47 PM.png

      I don't quite understand what is going on.
      Ideas?

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

        @VirtualVirgin you can‘t serialize a function, JSON is a data only format.

        VirtualVirginV 1 Reply Last reply Reply Quote 1
        • VirtualVirginV
          VirtualVirgin @Christoph Hart
          last edited by

          @Christoph-Hart said in Loading functions stored in an array from a JSON file is coming up "undefined":

          @VirtualVirgin you can‘t serialize a function, JSON is a data only format.

          Thanks, although I don't quite understand the premise.
          If the functions as code appear in the JSON file that was dumped, how does that same code not appear when the JSON is loaded?
          Is it changing format somehow?
          Conceptually I'm just behind.

          If I store the functions as const variables in an external .js file, then put those const variable references inside my array in the JSON file, would that then load correctly?

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

            @VirtualVirgin you‘re confusing JSON and Javascript. Javascript can define objects with functions as values but JSON can‘t. If you‘re storing and object somewhere it uses the JSON format.

            What you need to do is to define your functions in a Javascript object in your script and then just store the function name in the JSON that you export.

            VirtualVirginV 1 Reply Last reply Reply Quote 0
            • VirtualVirginV
              VirtualVirgin @Christoph Hart
              last edited by

              @Christoph-Hart said in Loading functions stored in an array from a JSON file is coming up "undefined":

              define your functions in a Javascript object in your script and then just store the function name in the JSON that you export.

              Thanks! I got it working now :)

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

              46

              Online

              1.7k

              Users

              11.7k

              Topics

              101.8k

              Posts