Skip to content

JSONObject.FromString() doc claims null return, but it throws an exception #10

@CallMeVerity

Description

@CallMeVerity

The documentation for JSONObject.FromString states:

@return Object handle, or null on failure

However, in the current version, FromString throws an exception on invalid JSON instead of returning null.

This breaks typical SourcePawn usage like:

JSONObject obj = JSONObject.FromString(message);
if (obj != null)
{
    // handle JSON
}
else
{
    // fallback if message is not JSON
}

Since SourcePawn has no try/catch mechanism, this makes it impossible to safely parse optional JSON or handle malformed input.

Suggested fixes:

  1. Restore the old behavior of returning null on invalid JSON.
  2. Implement alternatives methods that do not throw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions