Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 631 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Invalid JSON primitive" error when converting JSON file

#1
When trying to convert a JSON file via PowerShell:

$json = Get-Content "C:\folder1\test.txt"

$json | ConvertFrom-Json

write-output $json

I'm getting the following error:

> invalid json primitive : [.<br>
> (system.argunment.exception)
Reply

#2
I'm going out on a limb here, since you didn't provide your input data or the complete error message, but I guess that your problem is caused by a format mismatch between the output `Get-Content` provides and the input `ConvertFrom-Json` expects.

`Get-Content` reads the input file into an array of strings, whereas `ConvertFrom-Json` expects the JSON data in a single string. Also, piping `$json` into `ConvertFrom-Json` does not change the value of `$json`.

Change your code to the following and the error should disapear (provided there is no syntactical error in your input data):

$json = Get-Content 'C:\folder1\test.txt' | Out-String | ConvertFrom-Json

Write-Output $json
Reply

#3
You should check your JSON input file for characters that are not properly escaped with a "\"

I have also seen this issue with an input JSON file that was incorrectly formatted as follows:

{
Object1
}
{
Object2
}

Corrected format:

[{
Object1
},
{
Object2
}]

Once the format was corrected, I had no more issues.
Reply

#4
You will get this error if your input data starts like this:

data: [
{
...
},
{
...
}
]

You need to remove `data: ` (and only have `[`and `]` in this example):

[
{
...
},
{
...
}
]
Reply

#5
I was also receiving this error, and upon investigating my json file noticed that some of the JSON was invalid. I was ending the last object in an array with a comma like so:

[{ ..},]

Removing the comma fixed the issue for myself.

So in short, invalid JSON caused this issue for me.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through