status_reply(server_error(ErrorTerm), Out, HdrExtra, Context, Method, Code) :-
status_page_hook(server_error(ErrorTerm), 500, Context, JSON), % It is assuming JSON is a string
phrase(reply_header(json_status(server_error, JSON), HdrExtra1, Code), Header),
format(Out, '~s', [Header]),
print_html(Out, JSON). % Just used this predicate because it worked but need to investigate a better alternative
% ...
reply_header(json_status(Status, Tokens), HdrExtra, Code) -->
vstatus(Status, Code),
date(now),
header_fields(HdrExtra, CLen),
content_length(html(Tokens), CLen), % Is there another method to get content_length?
content_type(application/json, utf8),
"\r\n".