Announcement

Collapse
No announcement yet.

nsJSON plug-in

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

  • #31
    JSON does not really have comments AFAIK.

    The safest option is to use _mycomment:"comment text" style entries.

    If you still want a real comment then /**/ block comments probably have a higher chance of working across parsers...
    IntOp $PostCount $PostCount + 1

    Comment


    • #32
      This plugin is awesome.

      However, is there any chance of adding an escape function to convert an NSIS string into a JSON string?

      For example, right now if I call
      nsjson::Set some node path /value ":"
      Then the colon is not stored because it is invalid JSON, not a string. I have to call
      nsjson::Set some node path /value `":"`

      But if I don't know where the text has come from e.g.
      nsjson::Set some node path /value $R0
      Then that's a problem.

      One of the following would be ideal:
      nsjson::escape $R0
      Pop $R0
      nsjson::Set some node path /value $R0

      alternatively,
      nsjson::Set some node path /value /escape $R0

      Such a function shouldn't try to determine the type of data - just treat the input as an unescaped, unquoted string.

      Comment


      • #33
        Try quotes or double quotes around the variable? Like: "$R0". If strings have spaces, they can resolve to multiple arguments when used with a plugin, which is why quotes are needed.
        "Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
        NSIS 3 POSIX Ninja
        Wiki Profile

        Comment


        • #34
          1.1.0.1 - 23rd November 2015
          * Added Quote function.
          * Added amd64-unicode build.

          1.1.0.0 - 19th April 2015
          * Support for multiple JSON trees.
          * JSON via HTTP web requests.
          Somehow I hadn't uploaded the last version I'd been working on so I apologise for that. It includes built-in support for multiple JSON trees and HTTP web requests (e.g. for REST APIs).



          Stu

          Comment


          • #35
            This is great, thanks Stu

            Comment


            • #36
              NB: When you use nsJSON::Get /type, if the nodepath doesn't exist then nothing gets pushed onto the stack - so always make sure you check that the nodepath /exists before you try to get the type.

              Stu, you could change /type to return empty string if the node path doesn't exist, and do away with /exists altogether.

              Comment


              • #37
                Hey, Stu
                The new Quote function doesn't escape strings whose first and last characters are already quotemarks. For example, nsjson::Quote `"some"text"`

                Comment


                • #38
                  Originally Posted by Marshallx7 View Post
                  Hey, Stu
                  The new Quote function doesn't escape strings whose first and last characters are already quotemarks. For example, nsjson::Quote `"some"text"`
                  The output is:
                  "some\"text"
                  This is correct assuming the original feature request was to only surround the string in quotes if it isn't so already. Nevertheless:
                  1.1.0.2 - 9th December 2015
                  * Get function /type switch returns an empty string if the node does not exist.
                  * Added /always switch to Quote function which surrounds the input string in quotes even if it is already quoted.
                  Therefore, use the /always switch and the output will instead be:
                  "\"some\"text\""
                  http://nsis.sourceforge.net/File:NsJSON.zip

                  Stu

                  Comment


                  • #39
                    This is really great Stu, thanks.

                    Readme needs updating with latest switches behavior btw.

                    I have another feature request if you feel inclined:

                    { a: 'a', b: 1, c: {}}
                    nsJSON::Get /keys ...
                    Returns on the stack:
                    3
                    a
                    b
                    c

                    Comment


                    • #40
                      Originally Posted by Marshallx7 View Post
                      { a: 'a', b: 1, c: {}}
                      Erm, I would expect the plugin to deny this input, since it's invalid JSON
                      NSIS IDE for Atom | NSIS for Visual Studio Code | NSIS for Sublime Text | NSIS.docset

                      Comment


                      • #41
                        That was just an example of the JSON object in memory (as valid Javascript rather than JSON), not the string passed to nsJSON to build it. The point was the /keys feature request.

                        Comment


                        • #42
                          I have also found another case where nsJSON::Get does not return anything on the stack:
                          If you try to get something that doesn't exist (e.g. the specified /tree does not exist)

                          Please can this be changed to return empty string, to avoid stack corruption?

                          And I think that nsJSON:elete causes NSIS to crash if you try to delete something that doesn't exist.

                          Comment


                          • #43
                            The plug-in will set the error flag if the tree or node does not exist. If you think it is possible the tree or node may not exist, you should check the error flag before reading from the stack. Remember to clear the error flag first if necessary. The error flag is the only way to distinguish a definite error.

                            I have implemented /keys and fixed the Delete crash but I am working on a new feature for console application execution for JSON input/output so will upload a new version when done.

                            Stu

                            Comment


                            • #44
                              Awesome, thanks Stu!

                              Comment


                              • #45
                                Just discovered another crash, not sure if this is related to the previous crash in Delete:

                                nsJSON::Set /tree testTree testNode /value testValue
                                nsJSON::Get /tree testTree /exists /end
                                Pop $R0
                                MessageBox MB_OK $R0 ; "yes"
                                nsJSON:elete /tree testTree /end ; CRASH

                                Comment

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