HJSON usage problems

This topic contains 2 replies, has 2 voices, and was last updated by  PowershellVortex 2 months, 3 weeks ago.

  • Author
    Posts
  • #98395

    PowershellVortex
    Participant

    Hello,

    recently I've found HJSON and I think it's wonderful. But I have trouble during usage with PowerShell via c# implementation from https://github.com/hjson/hjson-cs.

    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: https://github.com/hjson/hjson-cs/blob/master/sample/test.hjson

    I've try to follow examples from Github Readme:

    0. Load into Powershell:

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

    it works, type [Hjson] is successfully loaded

    1. https://github.com/hjson/hjson-cs#read
    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?

  • #98844

    Don Jones
    Keymaster

    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?

  • #99433

    PowershellVortex
    Participant

    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: https://stackoverflow.com/questions/49783149/hjson-c-sharp-library-for-powershell
    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

You must be logged in to reply to this topic.