Announcement

Collapse
No announcement yet.

read json without nsjson

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • read json without nsjson

    in NSIS, I don't find native JSON support and I cannot use nsjson plugin. I have to use string instructions to read a json property.
    {
    "DATE" : "****",
    "BUILD_NUMBER" : ***,
    "RELEASE_STRING" : "***"
    }

    How do I read these json properties and store these values in the variable

  • #2
    StrCpy+StrLen+StrCmp in a custom parser.

    Why can't you use a plug-in?
    IntOp $PostCount $PostCount + 1

    Comment


    • #3
      plugin didnt work and last time in forum it was discussed it had some issues

      Comment


      • #4
        Works just fine
        PHP Code:
        Section "Prepare"
        InitPluginsdir
        FileOpen 
        $"$PluginsDir\temp.txt" w
        FileWrite 
        $'{"DATE" : "1234","BUILD_NUMBER" : 5678,"RELEASE_STRING" : 9.10}'
        FileClose $0
        SectionEnd  

        Section
        nsJSON
        ::Set /file "$PluginsDir\temp.txt"
        nsJSON::Get "DATE" /end
        Pop 
        $0
        nsJSON
        ::Get "BUILD_NUMBER" /end
        Pop 
        $1
        nsJSON
        ::Get "RELEASE_STRING" /end
        Pop 
        $2
        MessageBox mb_ok 
        $0,$1,$2
        SectionEnd 
        IntOp $PostCount $PostCount + 1

        Comment


        • #5
          I have a predetermined json file given like test.json which contains json properties. I cannot write it, but I am supposed to read values from predetermined json files. for that it does not work. if I have test.json in temp dir, i cannot read it.

          Comment


          • #6
            And what does this non-working file look like?
            IntOp $PostCount $PostCount + 1

            Comment


            • #7
              {
              "DATE" : ,
              "BUILD_NUM" : ,
              "RELEASE_STR" : ""
              }

              ABove would be format of given json file

              Comment


              • #8
                That is not valid JSON. Empty values should be "", null, or not present at all.
                IntOp $PostCount $PostCount + 1

                Comment


                • #9
                  my fault...I wanted to hide few info. the file will be something like this

                  {
                  "DATE" : "2022-03-06 08:45:36 +0000",
                  "BUILD_NUM" : "123",
                  "RELEASE_STR" : "1234/56"
                  }

                  Comment


                  • #10
                    Again, just works just fine for me:

                    PHP Code:
                    Section "Prepare"
                    InitPluginsdir
                    FileOpen 
                    $"$PluginsDir\temp.txt" w
                    FileWrite 
                    $'{$\n'
                    FileWrite $'"DATE" : "2022-03-06 08:45:36 +0000",$\n'
                    FileWrite $'"BUILD_NUM" : "123",$\n'
                    FileWrite $'"RELEASE_STR" : "1234/56"$\n'
                    FileWrite $'}$\n'
                    FileClose $0
                    SectionEnd  

                    Section
                    nsJSON
                    ::Set /file "$PluginsDir\temp.txt"
                    nsJSON::Get "DATE" /end
                    Pop 
                    $0
                    nsJSON
                    ::Get "BUILD_NUM" /end
                    Pop 
                    $1
                    nsJSON
                    ::Get "RELEASE_STR" /end
                    Pop 
                    $2
                    MessageBox mb_ok 
                    $0$\n$\n$1$\n$\n$2
                    SectionEnd 
                    Can you confirm if my code works for you?

                    Perhaps your file has a special encoding? UTF16? UTF8 with BOM?
                    IntOp $PostCount $PostCount + 1

                    Comment


                    • #11
                      the code works. but the problem is DATE, BUILD, RELEASE values keep changing evry day and I wouldn't know what the values are to write it into text file. At run time in my installer, i have to read from a .json file and output it into my file.

                      Comment


                      • #12
                        Section "Prepare" is not something you would use in your .nsi, it is just there to generate a example JSON file. The other section only cares about the names, not the value.
                        IntOp $PostCount $PostCount + 1

                        Comment


                        • #13
                          for some strange reasons, this does not seem to work for you. I could have attached my file. But there is no option to attach it.

                          Comment


                          • #14
                            There is a way to attach files. You might have to zip it.

                            Worst case, put a hex dump on pastebin.
                            IntOp $PostCount $PostCount + 1

                            Comment


                            • #15
                              got to know the reason... I have a key/property with an empty value... because of empty value "ABC" : [], it is not showing other values as well

                              guess it does not support empty arrays.

                              even in a single empty array, the plugin does not read the entire json file. that's unfortunate

                              Comment

                              Working...
                              X
                              😀
                              🥰
                              🤢
                              😎
                              😡
                              👍
                              👎