JSON parser very strict with allowed identifiers


#1

Hi,

The JSON parser gives a parsing error for the following JSON:

{
“image”: {
"@url": “http://www.last.fm/music/Bon+Jovi/+images/26760885"
#url2": “http://www.last.fm/music/Bon+Jovi/+images/26760885
}
}

While it may be that using @ and # within identifiers is not allowed, at least the last.fm api’s returns json that contains these characters. Is it possible to make the parser less strict and allow these two characters for identifiers? The change would be very simple, replace in juce_Identifier.cpp isValidIndentifier with:

bool Identifier::isValidIdentifier (const String& possibleIdentifier) noexcept
{
return possibleIdentifier.isNotEmpty()
&& possibleIdentifier.containsOnly (“abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#_-:”);
}

Patrick


#2

Ok, thanks - I’ll check that those characters don’t interfere with any other uses of the Identifier class, and if it’s ok, will add them.


#3

 

 

Hey Jules -

I just noticed that you can't use spaces in JSON keys either.  

I assume this is because you are using identifiers ... and it seems like a reasonable restriction.

However, I would point out that parsing JSON (JSON::Parse) with keys containing spaces seems to lead to an assertion failure on windows, but somehow not on mac.

 

 

Didn't dig enough to find the difference on the two systems, just cahnging my JSON instead.