• Products
    • Isadora
    • Get It
    • ADD-ONS
    • IzzyCast
    • Get It
  • Forum
  • Help
  • Werkstatt
  • Newsletter
  • Impressum
  • Dsgvo
  • Press
  • Isadora
  • Get It
  • ADD-ONS
  • IzzyCast
  • Get It
  • Press
  • Dsgvo
  • Impressum

Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags

    [ANSWERED] How do I Read and Decode a JSON Text File?

    How To... ?
    javascript
    4
    11
    2599
    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.
    • bonemap
      bonemap Izzy Guru last edited by mark

      [EDIT: edited the name of this thread to better indicate what the actual question is. -- Mark]

      Hi @DusX 

      I am having issues with the javascript actor on MBP 16" i9, Mac OSX 10.15.7 Catalina, Isadora 3.0.7 - 

      I am attempting to use the include txt file with javascript actor and am getting nowhere with parsing the simple code indicated in the tutorial "How to load external data with javascript".

      I am seeking to read .json files generated by Meshlab (example included below). As an extension .json is not included in the tutorial, I have attempted to change the extension to .txt - however, I am no closer to getting preformatted json files into Isadora. Any advice would be appreciated.

      fib.json.zip

      On top of that, I am experiencing some unstable behaviour with the javascript actor within the scene editor. 

      Best Wishes

      Russell

      http://bonemap.com | Australia
      Izzy STD 4.2 | USB 3.6 | + Beta
      MBP 16” 2019 2.4 GHz Intel i9 64GB AMD Radeon Pro 5500 8 GB 4TB SSD | 14.5 Sonoma
      Mac Studio 2023 M2 Ultra 128GB | OSX 15.3 Sequoia
      A range of deployable older Macs

      DusX 1 Reply Last reply Reply Quote 0
      • DusX
        DusX Tech Staff @bonemap last edited by DusX

        @bonemap

        This file uses read() to place the text contents of the json file into a variable. (include() runs the file contents as Javascript)
        Needs to be in the same folder as your JSON file.

        FIB-v1.izz

        Troikatronix Technical Support

        • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
        • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
        • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

        Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

        bonemap 1 Reply Last reply Reply Quote 1
        • bonemap
          bonemap Izzy Guru @DusX last edited by

          @dusx said:

          uses read() to place the text contents of the json file into a variable

           This is great. Is there a simple fix so that it reads the negative floats as well as the positive?

          Best Wishes

          Russell

          http://bonemap.com | Australia
          Izzy STD 4.2 | USB 3.6 | + Beta
          MBP 16” 2019 2.4 GHz Intel i9 64GB AMD Radeon Pro 5500 8 GB 4TB SSD | 14.5 Sonoma
          Mac Studio 2023 M2 Ultra 128GB | OSX 15.3 Sequoia
          A range of deployable older Macs

          DusX 1 Reply Last reply Reply Quote 0
          • DusX
            DusX Tech Staff @bonemap last edited by

            @bonemap said:

            fix so that it reads the negative floats

             OK, I missed that. I'm not sure. I just added a couple Print statements to make sure the data is read correctly, and that seems fine.
            So I have gone about breaking down the data another way (in steps) and I can see the last parsing step, where the ARRAY is parsed is where the negative signs are lost.
            I found this not so helpful article: javascript - JSON.parse fails for negative floating point numbers - Stack Overflow which suggest perhaps the '-' signs are of the wrong type.
            Since the Array is correct until the last step in this new file, perhaps some string parsing could be done to replace the '-' with a good one (if that's the case). Weirdly JSON validators are saying the JSON is good.
            FIB-v1.izz (same name).. just a quick update

            Troikatronix Technical Support

            • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
            • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
            • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

            Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

            1 Reply Last reply Reply Quote 1
            • Juriaan
              Juriaan Tech Staff last edited by

              Example Reading a JSON file with JavaScript / Parsing Object

              So in the following example, we are able to actually load in the JSON file and parse the object it gives with the 'vertices' field. (Why can't I select this with the JSON parser, feature request @DusX ?) Then we are able to actually take it further apart with the default JSON actors of Isadora.

              Isadora 3.1.1, Dell XPS 17 9710, Windows 10
              Interactive Performance Designer, Freelance Artist, Scenographer, Lighting Designer, TroikaTronix Community moderator
              Always in for chatting about interaction in space / performance design. Drop me an email at hello@juriaan.me

              Juriaan bonemap mark 3 Replies Last reply Reply Quote 2
              • Juriaan
                Juriaan Tech Staff @Juriaan last edited by

                @juriaan

                And of course, if you wish to parse the text to a valid number we just have to add this to a Text parser.

                value:float=.#

                Isadora 3.1.1, Dell XPS 17 9710, Windows 10
                Interactive Performance Designer, Freelance Artist, Scenographer, Lighting Designer, TroikaTronix Community moderator
                Always in for chatting about interaction in space / performance design. Drop me an email at hello@juriaan.me

                1 Reply Last reply Reply Quote 0
                • bonemap
                  bonemap Izzy Guru @Juriaan last edited by

                  @juriaan said:

                  select this with the JSON parser, feature request

                   Yes, I thought this too. A feature that allowed loading preformatted json files into the json plugin makes a lot of sense.

                  Thank you for the contribution.

                  Best wishes

                  Russell

                  http://bonemap.com | Australia
                  Izzy STD 4.2 | USB 3.6 | + Beta
                  MBP 16” 2019 2.4 GHz Intel i9 64GB AMD Radeon Pro 5500 8 GB 4TB SSD | 14.5 Sonoma
                  Mac Studio 2023 M2 Ultra 128GB | OSX 15.3 Sequoia
                  A range of deployable older Macs

                  DusX 1 Reply Last reply Reply Quote 0
                  • DusX
                    DusX Tech Staff @bonemap last edited by

                    @bonemap

                    This new file, mixes some of Juriaans', in a new approach that gets you your data. (2 methods shown, but the JS version is better in that I am returning the Array Length as well).

                    I think you should be able to work with this. FIB-v2.izz

                    Troikatronix Technical Support

                    • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
                    • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
                    • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

                    Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

                    bonemap 1 Reply Last reply Reply Quote 1
                    • bonemap
                      bonemap Izzy Guru @DusX last edited by

                      @dusx said:

                      Array Length

                       Yes, the array length is a useful / necessary parameter. Good to have!

                      Best wishes

                      Russell 

                      http://bonemap.com | Australia
                      Izzy STD 4.2 | USB 3.6 | + Beta
                      MBP 16” 2019 2.4 GHz Intel i9 64GB AMD Radeon Pro 5500 8 GB 4TB SSD | 14.5 Sonoma
                      Mac Studio 2023 M2 Ultra 128GB | OSX 15.3 Sequoia
                      A range of deployable older Macs

                      1 Reply Last reply Reply Quote 0
                      • mark
                        mark @Juriaan last edited by mark

                        @dusx @bonemap @juriaan

                        @juriaan asked:

                        Why can't I select this with the JSON parser, feature request @DusX?

                        Answer: you can.

                        I am sorry I'm joining this discussion so late, as it seems you all have gone through some gyrations that were really not necessary.

                        First, I thought the File Reader plugin was on the Add Ons (formally known as Plugins) page... but it's not. It is attached below. (I'll post it to the Add Ons page once you all give me some feedback that it's working OK.) This actor simply reads a file and outputs the text, which addresses the issue of getting the file data into the JSON Parser. (We can discuss whether or not file reading should be a built in thing on the JSON parser.. but for now, we'll let the File Reader plugin do it, OK?)

                        With the file reading addressed, I want to remind everyone that you can access any element in the JSON structure by using colon separated element names. Look at the help text for the 'select 1' input:

                        A string in the format xxx:yyy:zzz that selects a data member for the corresponding output, where xxx, yyy and zzz, can either be a key value or a numeric index. Items with only numeric digits are interpreted as an index. Items with non-numeric characters are interpreted as a key. Keys that consist only of numeric characters or that contain a colon must be enclosed in double quotes.
                        For example, the selector mark:3:leg 1 would attempt to get the top level element named 'mark', the third item inside of 'mark', and then a keyed value called 'leg 1' within that element.

                        Here's the text of Bonemap's original JSON file.

                        (FYI: the minus signs are totally OK and did not need to be converted, as Bonemap guessed above.)

                        {
                          "version" : "0.1.0",
                          "comment" : "Generated by MeshLab JSON Exporter",
                          "id"      : 1,
                          "name"    : "mesh",
                          "vertices" :                             **** VERTICES ELEMENT *****
                          [                                        **** ARRAY ELEMENT 0 *****
                            {
                              "name"       : "position_buffer",
                              "size"       : 3,
                              "type"       : "float32",
                              "normalized" : false,
                              "values"     :                       ***** VALUES ELEMENT ****
                              [
                                0.141067, 0, 0.99, -0.179258, -0.164215, 0.97, 0.0272986, 0.311054, 0.95, 0.223637,
                                -0.419697, -0.409579, -0.81, 0.0311997, 0.55689, -0.83, 0.333553, -0.407729, -0.856537
                              ]
                            }
                          ],
                          "connectivity" :
                          [
                          ],
                          "mapping" :
                          [
                          ],
                          "custom" : null
                        }
                        

                        I've marked the elements with asterisk enclosed labels above (these "comments" are not valid JSON!!!)

                        Grabbing the elements with names should be clear. But note that the inside of the "values" element is an array (marked by the square brackets) with one element. Array indexes are always zero based in the JSON Parser, so we use index 0 to get the array element, since it has no label.

                        With that in mind, to get that the list of values, you simply need to enter this in the 'select 1' input of the JSON Parser actor.:

                        vertices:0:values

                        and voilá, out come the 300 values stored in the fib.json file Bonemap originally posted.

                        I use a second JSON Parser actor to actually pull out the individual values. (This would be more efficient if the original JSON was really huge.)

                        So please try installing the File Reader plugin and then take a look at my sample patch below.

                        Best Wishes,
                        Mark

                        file-reader-v0.9.2.zip

                        read-json-with-file-reader-actor.zip

                        Media Artist & Creator of Isadora
                        Macintosh SE-30, 32 Mb RAM, MacOS 7.6, Dual Floppy Drives

                        bonemap 1 Reply Last reply Reply Quote 3
                        • bonemap
                          bonemap Izzy Guru @mark last edited by bonemap

                          @mark said:

                          feedback that it's working

                           Hi,

                          Brilliant! 

                          I will do some testing exchanging json files on the fly and see how that then propagates throughout a patch.

                          Best Wishes

                          Russell

                          http://bonemap.com | Australia
                          Izzy STD 4.2 | USB 3.6 | + Beta
                          MBP 16” 2019 2.4 GHz Intel i9 64GB AMD Radeon Pro 5500 8 GB 4TB SSD | 14.5 Sonoma
                          Mac Studio 2023 M2 Ultra 128GB | OSX 15.3 Sequoia
                          A range of deployable older Macs

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