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
read json without nsjson
16 posts
StrCpy+StrLen+StrCmp in a custom parser.
Why can't you use a plug-in?
Why can't you use a plug-in?
plugin didnt work and last time in forum it was discussed it had some issues
Works just fine
Section "Prepare"
InitPluginsdir
FileOpen $0 "$PluginsDir\temp.txt" w
FileWrite $0 '{"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 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.
And what does this non-working file look like?
{
"DATE" : ,
"BUILD_NUM" : ,
"RELEASE_STR" : ""
}
ABove would be format of given json file
"DATE" : ,
"BUILD_NUM" : ,
"RELEASE_STR" : ""
}
ABove would be format of given json file
That is not valid JSON. Empty values should be "", null, or not present at all.
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"
}
{
"DATE" : "2022-03-06 08:45:36 +0000",
"BUILD_NUM" : "123",
"RELEASE_STR" : "1234/56"
}
Again, just works just fine for me:
Perhaps your file has a special encoding? UTF16? UTF8 with BOM?
Section "Prepare"
InitPluginsdir
FileOpen $0 "$PluginsDir\temp.txt" w
FileWrite $0 '{$\n'
FileWrite $0 '"DATE" : "2022-03-06 08:45:36 +0000",$\n'
FileWrite $0 '"BUILD_NUM" : "123",$\n'
FileWrite $0 '"RELEASE_STR" : "1234/56"$\n'
FileWrite $0 '}$\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?
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.
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.
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.
There is a way to attach files. You might have to zip it.
Worst case, put a hex dump on pastebin.
Worst case, put a hex dump on pastebin.
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
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
Anders, can you please elaborate on StrCpy+StrLen+StrCmp for json files