HJSON usage problems

Hello,

recently I’ve found HJSON and I think it’s wonderful. But I have trouble during usage with PowerShell via c# implementation from GitHub - hjson/hjson-cs: Hjson for C#.

Since github repository doesn’t contain .dll, in order to test/help you need to compile project or download this compiled dll: https://ufile.io/phont

The test file which I use is: hjson-cs/test.hjson at master · hjson/hjson-cs · GitHub

I’ve try to follow examples from Github Readme:

  1. Load into Powershell:
$FilePath = ( Get-Item .\Hjson.dll ).FullName
[System.Reflection.Assembly]::LoadFrom("$FilePath")

it works, type [Hjson] is successfully loaded

  1. GitHub - hjson/hjson-cs: Hjson for C#
    c#:
var jsonObject = HjsonValue.Load(filePath).Qo();

Powershell:

$data = [Hjson.HjsonValue]::Load("$scriptRoot\test.hjson")
[Hjson.JsonUtil]::Qo($data)

it works but the output shows only keys but not values:

PS D:\OneDrive\PS-HJSON> $data = [Hjson.HjsonValue]::Load("$scriptRoot\test.hjson")
[Hjson.JsonUtil]::Qo($data)

Key       Value
---       -----
hello
text
text2
quote
otherwise
abc-123
commas
but
trailing
multiline
number
negative
yes
no
null
array
array2

and I can’t get values also like this:

$data.Values
#The following exception occurred while trying to enumerate the collection: "Operation is not valid due to the current state of the object."

the only way to get values is:

[Hjson.JsonUtil]::Qs($data,"hello")

but this is tedious and I’m sure that I’m missing something. So my general question is: the errors and behaviors are due the c# code/implementation? Or I’m using it in wrong way?

Sorry for this being a delayed reply; we were all busy at Summit.

Honestly, this is kind of so far outside the PowerShell orbit I’m not sure what to offer. Have you considered opening an issue on the project’s repo?

Hello Don, no need to apologize,

Indeed it’s outside of the scope of the Powershell, but I’ve asked also at the Powershell Slack/StactOverflow: HJSON C# library for PowerShell - Stack Overflow
and one of the developers with c# backgroud explain this issue and provide solution:

Just convert HJSON to json ( via provided method) as PowerShell is a lot better at handling that