WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: bottomleypotts on May 02, 2024, 09:37:33 PM

Title: JSON error
Post by: bottomleypotts on May 02, 2024, 09:37:33 PM
I have an issue with the attached json. jsValid returns a @False, however the json is valid and can be successfully parsed with jsParse. Does anyone have any idea what's wrong here??


AddExtender(`ilcjs44i.dll`)

json=FileGet(DirScript():`winbatch error.json`)

isJsonValid=jsValid(json)

j=jsParse(json)
mDiscord=jsConMap(j,@JsonValue)

Exit
Title: Re: JSON error
Post by: kdmoyers on May 03, 2024, 04:39:23 AM
Hmm. I don't see it either.  I do notice that passing through a pretty printer fixes it, but technically that should not matter?
If it were me, I'd start with the old chop-out-sections-until-the-error-goes-away method.
{
    "attachments": [
    ],
    "author": {
        "accent_color": null,
    },
    "channel_id": "1235547665495269898",
    "components": [
    ],
    "content": "This is a message",
    "edited_timestamp": null,
    "embeds": [
        {
            "color": 16760576,
            "content_scan_version": 0,
            "footer": {
                "text": "AFL tipping"
            },
            "timestamp": "2024-05-03T04:03:15+00:00",
            "type": "rich"
        }
    ],
    "flags": 0,
    "id": "1235779158681462834",
    "mention_everyone": false,
    "mention_roles": [
    ],
    "mentions": [
    ],
    "pinned": false,
    "referenced_message": null,
    "timestamp": "2024-05-03T04:03:20.035000+00:00",
    "tts": false,
    "type": 0
}
Title: Re: JSON error
Post by: td on May 03, 2024, 07:13:05 AM
AddExtender(`ilcjs44i.dll`)

json=FileGet(DirScript():`winbatch error.json`)

Json = StrTrimChar(Json, @lf)

isJsonValid=jsValid(json)

j=jsParse(json)
mDiscord=jsConMap(j,@JsonValue)

Exit
Title: Re: JSON error
Post by: bottomleypotts on May 04, 2024, 11:43:45 PM
Yep, that makes sense. I have looked at this problem for days and not been able to see it!
Title: Re: JSON error
Post by: td on May 05, 2024, 08:48:55 AM
The jsIsValid function should handle the removal of trailing white space for you. However, a standard library string class method used to implement this functionality did not work as expected. This prevented the function from cleaning up the input before calling the extender's "null" parser to validate the JSON data. A corrected version of the extender should be posted tomorrow if all goes as planned.

Thanks for bringing this to our attention.