Skip to content
⌘ NSIS Forum Archive

Create a JSON variable in an NSIS script

7 posts

Re DeL SiLeNziO#

Create a JSON variable in an NSIS script

Hi all,
I'm a new user of this forum and I'm a newbie of NSIS installer and JSON.
Unfortunately, I've to make an NSIS script that, taking values from a form in the installer, will create a JSON, in order to make an http request.

The question is, it is possible to create a json variable in nsis? All threads I've seen, talking about a json file for input, but in this case, I should have a json variable for output.
It is possible? I took a look to nsJSON plugin, but I don't know if it is the right plugin..

Thanks!
Re DeL SiLeNziO
jpderuiter#
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
Re DeL SiLeNziO#
mmm ok, I've already read this thread but I need some explaination...

the example of thread says:

nsJSON::Set `more_stuff` `PSCHED_009_NAME` /value `QoS Packet Scheduler`
in this case, where is the variable containing my data?
How can I do an http call?
Re DeL SiLeNziO#
I tried to use nsJSON but, when compile I obtain:
Invalid command: nsJSON::Set
this is my code:
...
!include MUI2.nsh
....
Page custom nsDialogsPage
...
Function nsDialogsPage
SetOutPath "$INSTDIR\bin"
File "..\bin\nsJSON.dll"

nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateLabel} 0 0 100% 12u "Registering a new AIC"
Pop $Title

${NSD_CreateLabel} 0 20 20 12u "AIC:"
Pop $LabelAIC
${NSD_CreateText} 40 20 80 12u ""
Pop $TextAIC

${NSD_GetText} $TextAIC $prova

nsJSON::Set /value `{}`
nsJSON::Set `aic` /value `"$prova"`
nsJSON::Serialize /format /file c:\Temp\test.json
DetailPrint `Generate: c:\Temp\test.json`

nsDialogs::Show
FunctionEnd

Should I include anything else?!
Re DeL SiLeNziO#
Originally Posted by Anders View Post
Invalid command probably means it cannot find the plugin, use !addplugindir...
Ok!! Thanks! With addplugindir works!
In order to take the value of my ${NSD_CreateText} I used NSD_GetText:
...
Var a
...
${NSD_CreateText} 40 20 80 12u ""
Pop $txt

${NSD_GetText} $txt $a

nsJSON::Set /value `{}`
nsJSON::Set `VARTEXT` /value `"$a"`
nsJSON::Serialize /format /file c:\Temp\test.json
DetailPrint `Generate: c:\Temp\test.json`
but, even if I write some text in the field my var $a is empty and my json result is:

{
"VARTEXT": ""
}
Where is the error?! 🙁 😢

thanks so much!!!!