I took a look at this over the weekend. Based on the existing code in hhvm only the json_decode pathway needs to be replaced. encoding is implemented independently and shares a common pathway with a variety of other serializations. I've gone ahead and done the initial work of porting over the linked pecl extension's json_decode into hhvm's codebase[1]. There are two issues that i'm not sure how to solve:
1) the json_encode pathway doesn't need to be replaced, but it does make a single method call[2] to a function from the previous library:
void utf16_to_utf8(HPHP::StringBuffer &buf, unsigned short utf16);
I don't really know enough in this realm to go about re-implementing this. It takes the unsigned short and append its utf-8 representation to the buffer. hhvm does have an intl_convert_utf16_to_utf8 method, but it works on full strings so passing it two bytes at a time would be undesirable.
2) hhvm has a special mode FB_LOOSE which allows invalid json. json-c has a strict mode which i've only enabled when FB_LOOSE is not set, but this does not pass their unit tests of previously accepted invalid json. I have not changed the method signatures between the json extension and the parser, rather implemented the existing method signatures with the json-c parser, so with a bit more work json-c could just be a compile time flag, but not sure i like that solution either.
Suggestions?
Erik B.