Adapted from https://github.com/OSGeo/gdal/pull/277, tested with json-c 0.12 and 0.13. Similar diff from bket@