none
Error when converting from json

    Question

  • Hi,

    when I want to convert string from json (using ConvertFrom-Jsond) one bigger file (64KB), I recieve an error "ConvertFrom-Json : Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.".

    I have read how to configure the property in web.config. But how to configure it in .ps1 file?

    Thanks

    Michal Stoppl


    • Edited by MStoppl Monday, June 03, 2013 1:18 PM
    Monday, June 03, 2013 1:17 PM

Answers

  • Hi Michal,

    you can try the .net way ;-)

    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")        
    $jsonserial= New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer 
    $jsonserial.MaxJsonLength = $somevalue
    $Obj = $jsonserial.DeserializeObject($rawtext)
    Malte

    Monday, June 03, 2013 3:06 PM

All replies

  • Hi Michal,

    you can try the .net way ;-)

    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")        
    $jsonserial= New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer 
    $jsonserial.MaxJsonLength = $somevalue
    $Obj = $jsonserial.DeserializeObject($rawtext)
    Malte

    Monday, June 03, 2013 3:06 PM
  • Something is strange...

    I've set $somevalue to 100000 and size of $rawtext is about 63KB. But I still get the same error. I have configured $somevalue to even higher value, but without success....

    Anyway a very good idea, thanks

    M.

    • Edited by MStoppl Tuesday, June 04, 2013 2:42 PM
    Tuesday, June 04, 2013 2:38 PM
  • Hi M.,

    this is strange... you can try to set se value to max with:

    $jsonserial.MaxJsonLength = [int]::MaxValue

    Malte

    Tuesday, June 04, 2013 3:14 PM
  • It helped. Thanks a lot.

    ------- Michal Stoppl

    • Edited by MStoppl Wednesday, June 05, 2013 9:41 AM
    Wednesday, June 05, 2013 9:40 AM