Powershell and Json

Welcome Forums General PowerShell Q&A Powershell and Json

This topic contains 3 replies, has 3 voices, and was last updated by

2 years, 3 months ago.

  • Author
  • #63514

    Topics: 4
    Replies: 5
    Points: 21
    Rank: Member

    I am newb at powershell.

    I am using powershell to get a json object out of my database.

    I am getting the json out of my database ok and I can display it to the powershell console. But I am attempting to format that json into a readable form.

    I understand the convertFrom-Json cmdlet. But when I run it I am a getting an exception that says:

    ConvertFrom-Json : Unterminated string passed in.

    This what I have in my powershell script:

    $sql = "SELECT CAST(Content as VARCHAR(max)) AS Content FROM %$^%$ WHERE @#$#@ = 2"

    $row = Invoke-Sqlcmd -Query -ServerInstance $#@#! -Database $#@#! -Username $#@#! -Password $#@#! -QueryTimeout 300

    [string] $content = $row.Content

    Write-Output $content | ConvertFrom-Json

    Any thoughts, I have read a ton of articles about this.


  • #63570

    Topics: 0
    Replies: 669
    Points: 0
    Rank: Member

    What's in $content. Can you show that?

    • #63634

      Topics: 4
      Replies: 5
      Points: 21
      Rank: Member

      Thanks for your interest in helping me.

      $content is the json object that looks similar to this except their are a bunch of escape characters:

      {"glossary": { "title": "example glossary","GlossDiv": {"title": "S","GlossList": {"GlossEntry": { "ID": "SGML","SortAs": "SGML","GlossTerm": "Standard Generalized Markup Language","Acronym": "SGML","Abbrev": "ISO 8879:1986","GlossDef": { "para": "A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso": ["GML", "XML"] },"GlossSee": "markup" }}}}

      Thanks so much!

  • #63640

    Topics: 12
    Replies: 215
    Points: 381
    Helping Hand
    Rank: Contributor

    So what happens if you copy the example you posted to a file and then add the escape characters back in, does it still work to use convertfrom-json?

The topic ‘Powershell and Json’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort