ParseJSON fails with "Unexpected end of input error" message if the given string is longer than 4096 byte.
Is there any chance to increase this limit?
ParseJSON Unexpected end of input error (4K limit)
ParseJSON Unexpected end of input error (4K limit)
-= endo (registered user of purebasic since 98) =-
Re: ParseJSON Unexpected end of input error (4K limit)
Do you have an example?
This works as expected and is much longer than 4k:
This works as expected and is much longer than 4k:
Code: Select all
If ParseJSON(0, Chr(34) + Space(1000000) + Chr(34))
Debug Len(GetJSONString(JSONValue(0)))
Else
Debug JSONErrorMessage()
EndIf
quidquid Latine dictum sit altum videtur
Re: ParseJSON Unexpected end of input error (4K limit)
I think it's a Friday the 13th thing ( bad Jason )
Norm

Code: Select all
If ParseJSON(0, Chr(34) + Space(1000000) )
Debug Len(GetJSONString(JSONValue(0)))
Else
Debug JSONErrorMessage()
EndIf
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Re: ParseJSON Unexpected end of input error (4K limit)
Here is my whole application code,
It reads from console data or program arguments, decode the json string and pretty-print it to console output.
I use it like:
All the above works if the given string is not longer than 4096 bytes
I tried with/without compiling unicode exe and #PB_Ascii / #PB_UTF8 flags for PEEKS.
It reads from console data or program arguments, decode the json string and pretty-print it to console output.
I use it like:
Code: Select all
more myfile.json | json.exe
or
json.exe < myfile.json
or
json.exe <some-json>
or
curl myurl | json.exe
Code: Select all
If OpenConsole()
If CountProgramParameters() > 0
val.s = ProgramParameter()
Else
*Buffer = AllocateMemory(32768)
ReadSize = ReadConsoleData(*Buffer,32768)
If ReadSize = 32768
PrintN("Buffer overflow (max 32KB)")
FreeMemory(*Buffer)
CloseConsole()
End
ElseIf ReadSize > 0
val = Trim(PeekS(*Buffer,ReadSize,#PB_Ascii))
EndIf
EndIf
If CreateJSON(0)
If ParseJSON(0,val,#PB_JSON_NoCase)
val = ComposeJSON(0, #PB_JSON_PrettyPrint)
PrintN(val)
SetClipboardText(val)
Else
PrintN("> " + JSONErrorMessage())
PrintN(Str(Len(val)))
PrintN(val)
EndIf
EndIf
CloseConsole()
EndIf
-= endo (registered user of purebasic since 98) =-
Re: ParseJSON Unexpected end of input error (4K limit)
Hm...,
this:
works for me with a file of 4657 bytes. (win7 x64 PB 5.41 x86 compiled as unicode)
Bernd
this:
Code: Select all
EnableExplicit
Define Val$, *Buffer, ReadSize.i
If OpenConsole()
If CountProgramParameters() > 0
Val$ = ProgramParameter()
Else
*Buffer = AllocateMemory(1024)
If *Buffer
Repeat
ReadSize = ReadConsoleData(*Buffer, 1024)
If ReadSize > 0
val$ = Trim(PeekS(*Buffer, ReadSize, #PB_Ascii))
EndIf
Until ReadSize = 0
FreeMemory(*Buffer)
EndIf
EndIf
If Len(Val$) > 0
If CreateJSON(0)
If ParseJSON(0, val$, #PB_JSON_NoCase)
val$ = ComposeJSON(0, #PB_JSON_PrettyPrint)
PrintN(val$)
SetClipboardText(val$)
Else
PrintN("Error> " + JSONErrorMessage())
PrintN("-------------")
PrintN("Length: " + Str(Len(val$)))
PrintN(val$)
EndIf
FreeJSON(0)
EndIf
EndIf
CloseConsole()
EndIf
Code: Select all
JsonParser < test.json
Last edited by infratec on Mon Jan 25, 2016 7:53 am, edited 1 time in total.
Re: ParseJSON Unexpected end of input error (4K limit)
Your problem is that ReadConsoleData() may not return all data in one call. You have to use a loop. The help for ReadConsoleData() contains an example how to do this.
quidquid Latine dictum sit altum videtur
Re: ParseJSON Unexpected end of input error (4K limit)
Changed my listing above.
Bernd
Bernd
Re: ParseJSON Unexpected end of input error (4K limit)
@freak: Got it! Thank you. It solved my problem.
Here is my Pretty Print Json dos command source code, very useful to test web services that returns json
Here is my Pretty Print Json dos command source code, very useful to test web services that returns json
Code: Select all
#maxSize = 64 ;64KB
If OpenConsole()
If CountProgramParameters() > 0
val.s = ProgramParameter()
Else
pos = 0
*Buffer = AllocateMemory(1024 * #maxSize)
For i=1 To #maxSize
ReadSize = ReadConsoleData(*Buffer + pos, 1024)
pos + ReadSize
If ReadSize = 0
Break
EndIf
Next
If i = #maxSize
PrintN("Buffer overflow, max: " + Str(#maxSize))
FreeMemory(*Buffer)
CloseConsole()
End
EndIf
val = Trim(PeekS(*Buffer,pos,#PB_UTF8))
EndIf
If val <> "" And CreateJSON(0)
If ParseJSON(0,val,#PB_JSON_NoCase)
val = ComposeJSON(0, #PB_JSON_PrettyPrint)
PrintN(val)
SetClipboardText(val)
Else
PrintN("Error: " + JSONErrorMessage())
EndIf
Else
PrintN("Error: Cannot initialize JSON object or empty input.")
EndIf
CloseConsole()
EndIf
-= endo (registered user of purebasic since 98) =-