mevdschee / php-crud-api

Single file PHP script that adds a REST API to a SQL database
MIT License
3.59k stars 1.01k forks source link

New Entity returns non JSON Integer/String value #75

Closed maschhoff closed 8 years ago

maschhoff commented 8 years ago

Dear Developer,

i´ve tested you´re code which is great but, in one case it´s not round up JSON / REST technology. If you create a new entity with post you will get as return an integer with the new id. But this id is in non JSON format. Better format would be {result:+id+}

Thanks!

mevdschee commented 8 years ago

Thank you for your bug report.

AFAIK a single number is valid JSON.

JSON lint agrees, see: http://jsonlint.com/

Where did you find that it is not?

mevdschee commented 8 years ago

Ok, I've read RFC 4627 (see: http://www.ietf.org/rfc/rfc4627.txt) and indeed it is a JSON-value and not JSON-text.

mevdschee commented 8 years ago

Okay, I think I have the full picture now.

According to JSON validator (see: https://jsonformatter.curiousconcept.com/) it is valid in RFC 7159 (http://www.ietf.org/rfc/rfc7159.txt).

It seems it is a valid JSON-text according to RFC 7159 (2014) and not according to RFC 4627 (2006).

I think in practice all parsers accept this as valid JSON. Can you tell me which JSON parsers reject this response as valid JSON? If there are any/many I will (re)consider adjusting the output.