Skip to main content
edited tags
Link
Kevin Montrose
  • 18.7k
  • 6
  • 35
  • 62

StackExchange API withcalls that return select post body returns Json errorbodies throw JSON errors

We are calling StackExchange API to get some Stackoverflow forum data for research. When calling the Stack Exchange API to get the post body, it will return an error for some threads, e.gposts. https://api.stackexchange.com/docs/questions#page=13&pagesize=100&fromdate=2013-09-01&todate=2013-09-02&order=asc&sort=creation&filter=!9ciXf5l7v&site=stackoverflow&run=true (EG:
https://api.stackexchange.com/docs/questions#page=13&pagesize=100&fromdate=2013-09-01&todate=2013-09-02&order=asc&sort=creation&filter=!9ciXf5l7v&site=stackoverflow&run=true9ciXf5l7v&site=stackoverflow) throws:

But if we exclude the post body by calling this API, https://api.stackexchange.com/docs/questions#page=13&pagesize=100&fromdate=2013-09-01&todate=2013-09-02&order=asc&sort=creation&filter=default&site=stackoverflow&run=true (https://api.stackexchange.com/docs/questions#page=13&pagesize=100&fromdate=2013-09-01&todate=2013-09-02&order=asc&sort=creation&filter=default&site=stackoverflow&run=true), it works fine.

Invalid JSON returned


But if we exclude the post body, EG: [/docs/questions#page=13&pagesize=100&fromdate=2013-09-01&todate=2013-09-02&order=asc&sort=creation&filter=default&site=stackoverflow][2] , it works fine.

We suspect it’s because the post body contains some characters like “\0” which makes the returned jsonJSON invalid.

API calls that return select post bodies throw JSON errors

When calling the Stack Exchange API to get the post body, it will return an error for some posts. EG:
/docs/questions#page=13&pagesize=100&fromdate=2013-09-01&todate=2013-09-02&order=asc&sort=creation&filter=!9ciXf5l7v&site=stackoverflow throws:

Invalid JSON returned


But if we exclude the post body, EG: [/docs/questions#page=13&pagesize=100&fromdate=2013-09-01&todate=2013-09-02&order=asc&sort=creation&filter=default&site=stackoverflow][2] , it works fine.

We suspect it’s because the post body contains some characters like “\0” which makes the returned JSON invalid.