Old 11th February 2016, 10:26   #41
Marshallx7
Junior Member
 
Join Date: Oct 2012
Posts: 35
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.
Marshallx7 is offline   Reply With Quote
Old 12th February 2016, 16:59   #42
Marshallx7
Junior Member
 
Join Date: Oct 2012
Posts: 35
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.
Marshallx7 is offline   Reply With Quote
Old 15th February 2016, 11:24   #43
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 15th February 2016, 11:27   #44
Marshallx7
Junior Member
 
Join Date: Oct 2012
Posts: 35
Awesome, thanks Stu!
Marshallx7 is offline   Reply With Quote
Old 16th February 2016, 15:19   #45
Marshallx7
Junior Member
 
Join Date: Oct 2012
Posts: 35
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::Delete /tree testTree /end ; CRASH
Marshallx7 is offline   Reply With Quote
Old 29th February 2016, 15:32   #46
Marshallx7
Junior Member
 
Join Date: Oct 2012
Posts: 35
I'm also having trouble using the unicode version of the plugin:

code:
OutFile "test.exe"
!define SETTING_UNICODE
!ifdef SETTING_UNICODE
Unicode true
!addplugindir /x86-unicode "./plugins/x86-unicode"
!else
Unicode false
!addplugindir /x86-ansi "./plugins/x86-ansi"
!endif
Page instfiles
Function .onInit
nsjson::set /tree testTree testNode /value testValue
nsjson::get /tree testTree testNode /end
Pop $R0
MessageBox MB_OK $R0 ; "testValue"
FunctionEnd
Section "dummy"
SectionEnd



With the ansi version, the message box reads "testValue" as expected, but with the unicode version is just says "t".
Marshallx7 is offline   Reply With Quote
Old 1st March 2016, 19:56   #47
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 854
Quote:
Originally Posted by Marshallx7 View Post
I'm also having trouble using the unicode version of the plugin:

code:
OutFile "test.exe"
!define SETTING_UNICODE
!ifdef SETTING_UNICODE
Unicode true
!addplugindir /x86-unicode "./plugins/x86-unicode"
!else
Unicode false
!addplugindir /x86-ansi "./plugins/x86-ansi"
!endif
Page instfiles
Function .onInit
nsjson::set /tree testTree testNode /value testValue
nsjson::get /tree testTree testNode /end
Pop $R0
MessageBox MB_OK $R0 ; "testValue"
FunctionEnd
Section "dummy"
SectionEnd



With the ansi version, the message box reads "testValue" as expected, but with the unicode version is just says "t".
Sounds like you are using the ansi version for both ansi and unicode installers.

By the way, if the plugins are copied correctly to both '${NSISDIR}\plugins\x86-ansi' and '${NSISDIR}\plugins\x86-unicode', then you don't need to use !addplugindir. 'Unicode True' does that work for you.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 1st March 2016, 22:35   #48
Marshallx7
Junior Member
 
Join Date: Oct 2012
Posts: 35
Nope, confirmed I am using the correct builds. DLLs are stored in local plugins directory, not in NSISDIR, hence the use of addplugindir. Does this work for you?
Marshallx7 is offline   Reply With Quote
Old 1st March 2016, 22:52   #49
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 854
No it doesn't work for me, it's showing the same as what you are getting.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 1st March 2016, 22:54   #50
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,610
When something in a ANSI installer is unexpectedly a single character then it is a clear indication that something was not converted from Unicode to ANSI. The other way around could be anything, a plugin mismatch or bug. A missing conversion bug to Unicode usually looks Chinese.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 4th March 2016, 15:56   #51
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Quote:
1.1.0.3 - 4th March 2016
* Fixed crash for the Delete function when specifying a tree/path that
does not exist.
* Fixed Unicode build.
* Added /keys switch to Get function.
http://nsis.sf.net/File:NsJSON.zip

I am still working on the process exec code.

Stu
Afrow UK is offline   Reply With Quote
Old 16th April 2016, 20:16   #52
Marshallx7
Junior Member
 
Join Date: Oct 2012
Posts: 35
Yep, Unicode works fine now, thanks Stu.

I have another feature request:
It would be great if /index accepted negative numbers to get/set/delete from the end of an array/node.
For example, /index -1 means the last element, /index -2 means the second-last element and so on.

Right now, this is achieved by getting the count of elements, decrementing, then getting/setting/deleting the required element. A negative index would streamline this process.
Marshallx7 is offline   Reply With Quote
Old 10th August 2016, 10:14   #53
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Quote:
1.1.0.5 - 10th August 2016
* Empty value keys ("") were not included in serialized JSON.
* Serialize function popped one extra value from the stack.

1.1.0.4 - 7th June 2016
* Fixed incorrect flags used for HTTP requests.
* Added support for negative indices.
* Added console application execution for input and output.
* Added support for asynchronous HTTP requests and console application
execution.
http://nsis.sf.net/File:NsJSON.zip

Stu
Afrow UK is offline   Reply With Quote
Old 5th October 2016, 07:38   #54
awall
Junior Member
 
Join Date: Feb 2014
Posts: 2
Output NodePath not cleared when response is empty?

Hi Stu,
started using nsJSON recently, very nice work!

I'm facing an issue using HTTP web requests:
code:
nsJSON::Set /tree Request /value `{ "Url": "${myURI}", "Verb": "POST", "DataType": "JSON" }
nsJSON::Set /tree Response /http Request


The REST method I'm calling in the "Url" may have an empty response (e.g. only returns 200 OK).
In such case, the returned Response tree has the "Output" node populated with the response from the previous call to another REST method, instead of returning an empty "Output" node.

Is this a bug or am I missing something?

Thanks
Andrea
awall is offline   Reply With Quote
Old 14th October 2016, 08:14   #55
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
I have uploaded a new version which fixes the issue.

http://nsis.sourceforge.net/File:NsJSON.zip

Stu
Afrow UK is offline   Reply With Quote
Old 1st November 2016, 22:49   #56
Marshallx7
Junior Member
 
Join Date: Oct 2012
Posts: 35
I'm having a problem with the latest build where nsJSON::Serialize is leaving the filepath on the stack. I know there was an issue fixed recently where one too many values were popped but now the reverse seems to be true...

I suspect that the old code was always popping file, even if it wasn't needed, whereas the new code pushes it back on the stack even if it was needed

On a separate note, I have found that doing an http request with Verb=POST and DataType=JSON sends a request where the post data is unicode with Content-Type: application/x-www-form-urlencoded
Is there a way to get this to send as UTF-8 with Content-Type: application/json ?

Thanks

Last edited by Marshallx7; 2nd November 2016 at 00:20. Reason: extra request
Marshallx7 is offline   Reply With Quote
Old 27th September 2017, 13:13   #57
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,610
How are you supposed to delete a tree? Especially the "default"? tree?

Quote:
nsJSON::Set /value '{ "Input": [ { "test1": false, } ] }'
nsJSON::Delete /end # <-- Crash on exit!
Quote:
nsJSON::Set /value '{ "Input": [ { "test1": false, } ] }'
nsJSON::Delete "" /end # <-- Does nothing
Quote:
nsJSON::Set /value '{ "Input": [ { "test1": false, } ] }'
nsJSON::Set /value '{}' # <-- "Works"

nsJSON::Set /value '[]'
nsJSON::Set /value '{ "Input": [ { "test1": false, } ]' # Not valid JSON now?
nsJSON::Set /value '{}' # <-- Now it fails
Quote:
nsJSON::Delete /tree "" /end # <-- Crash

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 27th October 2017, 08:21   #58
Victor4
Junior Member
 
Join Date: Oct 2017
Posts: 2
Good job!
Try this tool: JSON formatter
Victor4 is offline   Reply With Quote
Old 21st November 2017, 10:37   #59
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Quote:
Originally Posted by Anders View Post
How are you supposed to delete a tree? Especially the "default"? tree?
Quote:
1.1.1.0 - 21st November 2017
* Fixed JSON with syntax errors still being parsed without setting the error flag.
* Fixed Set function not replacing the root value if the value was an array.
* Fixed Delete function not deleting the root node and tree.
http://nsis.sourceforge.net/File:NsJSON.zip

Anders, please let me know if this resolves all your issues. Apologies for the wait.

This will delete the root node and tree:
code:
nsJSON::Delete /end


Stu
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Tags
json, plug-in

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump