Class InvalidJSON

Running QnA 9.5.13 on Windows 2016. Any idea why the “of json” inspector doesn’t like this json? thanks

   Q: lines of file "c:\out2.text"
    A: {"HostId": "123456", "Cores": "2"}
    T: 7165

    Q: json of file "c:\out2.text"
    E: The expression could not be evaluated: class InvalidJSON
    T: 1071

Curious.

image

Running on Windows 10

Q: lines of file "x:\trn\test.json"
A: {"HostId": "123456", "Cores": "2"}
T: 1.543 ms
I: plural file line

Q: json of file "x:\trn\test.json"
A: {"Cores":"2","HostId":"123456"}
T: 0.762 ms
I: singular json value

Same version of the debugger, different OS, different behaviour.

can you try launching a powershell command on Win10 then run the command line qna.exe rather than the Fixlet Debugger UI? That’s what I am doing and maybe you’ll see the same results

seems to work for me on Win2016 (pre-release build in my lab…)

Also working on Windows 10 laptop on debugger 9.5.13.130

1 Like

and QnA.exe tool as well

Maybe we need a little more detail about exactly how you’re running it. I wonder if you are using command lines in a way that PowerShell is interpreting the {} characters instead of passing them to QNA?

and launched via powershell.

And on 2016

Does qna.exe require anything special in the user profile? I’m connecting to an AWS Win2016 instance and then connecting the the console via session manager which only returns me a powershell session. From there I am running qna.exe from the BES Client directory.

Fixlet Debugger drops some HKCU keys but I don’t think that qna.exe does anything funky with the profiles.
I wonder if there might be an encoding issue with your out2.txt file?

I wonder if you are hitting some permissions thing with the BigFix client folder and it’s contents?
your path (x:) suggests a mapped drive?

My files are on c:, x:\ was @trn testing

I recreated my .json file manually from my original post by copy/pasting the text and QnA inspections the json with success. So I think maybe there is some strange encoding in my file

This is how I am generating it:

		delete __createfile
		delete getmetadata.ps1
				
		createfile until _EOF
		$instanceid=(Invoke-WebRequest -UseBasicParsing -URI http://169.254.169.254/latest/meta-data/instance-id).Content
		$obj = [PSCustomObject]@{
		    'instance-id' = $instanceid
		    }
		$obj | ConvertTo-Json > c:\out2.text
		_EOF
		
		copy __createfile getmetadata.ps1
		waithidden powershell.exe -executionpolicy remotesigned -File getmetadata.ps1
		continue if {exit code of action = 0}

I assume something in that powershell json formatting is wrong so that’s what I’m going to look at next.

Got it fixed. When I was finally able to open my json file up with a good text editor, I found the encoding was UCS-2 LE BOM. Getting powrshell to properly encode the output was the answer:

$instanceid=(Invoke-WebRequest -UseBasicParsing -URI http://169.254.169.254/latest/meta-data/instance-id).Content
$json = @{'instance-id' = $instanceid} | ConvertTo-Json -Depth 99
$json | out-file -encoding ascii c:\out2.json

thanks for everyone’s help.

2 Likes

Sorry for bumping an old thread but I found this posting after encountering issues reading a unicode encoded json. In case it helps anyone else that finds this thread, one way I found to workaround the unicode file encoding is read the lines of the file then concatenate and cast the string as a json.

Q: jsons of file "C:\test_unicode.json"
E: The expression could not be evaluated: class InvalidJSON

Q: lines of file "C:\test_unicode.json" 
A: {"HostId": "123456", "Cores": "2"}
T: 0.644 ms
I: plural file line

Q: json of concatenation " " of lines of file "C:\test_unicode.json" 
A: {"Cores":"2","HostId":"123456"}
T: 0.344 ms
I: singular json value
4 Likes