deserializeJson throwing error on seemingly valid JSON data

Description

take this JSON response from an HTTP API:

{
"error": null,
"token": null,
"statusVersion": 2,
"statusCode": "succeeded",
"percentProgress": null,
"statusText": null,
"result": {
"totalSizeMB": 25877,
"databaseFileSizeMB": 172,
"contentFileSizeMB": 25501,
"indexFileSizeMB": 204,
"numberOfMessages": 126212
},
"logOutput": null
}

Looks valid to me, also jsonlint.com etc. validate it correctly.

isJson is giving false for the JSON below, and deserializeJson is throwing this error:

Syntax Error, Invalid Construct
at position 1 in [{
"error": null, ...]

Environment

CentOS 7.9, OpenJDK 11, Lucee Express

Activity

Show:

Zac Spitzer 3 August 2021 at 17:56

Ok, linked and closing as a duplicate

Christian Meis 3 August 2021 at 17:47
Edited

Yes, the first character I’m filtering out is the BOM (chr(65279)).

Seems to be exactly https://luceeserver.atlassian.net/browse/LDEV-2449 , not sure why this one didn’t turn up in my search before opening this issue (must be a case of PEBKAC…).

Just for clarification: my data is gathered by cfhttp-ing to a REST API, so not reading from a file, but exactly as described in the quoted ticket…

Brad Wood 3 August 2021 at 17:08

Yeah, a BOM was my first guess. Especially if the JSON is being read from a file.

Use some code like this to tell us the exact ASCII codes in the first 10 chars of the string.

 

var myString = 'Hello World'; loop from=1 to=10 index='local.i' { dump( asc( myString[i] ) ) }

Zac Spitzer 3 August 2021 at 15:40
Edited

what’s the character you’re stripping out?

this might the problem? https://luceeserver.atlassian.net/browse/LDEV-2449

Christian Meis 3 August 2021 at 15:09

Yep, there’s definitely “something at the start of the returned result: A simple deserializeJson(right(cfhttp.filecontent,len(cfhttp.filecontent)-1)) does the trick and returns a correct decoded struct.

I still think Lucee should be able to cope with the result, how can I hep debug this further? (Still assuming that the missing charset in the result somehow is triggering this?!)

Duplicate

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 30 July 2021 at 07:50
Updated 3 August 2021 at 17:56
Resolved 3 August 2021 at 17:55