PostgreSQL Source Code  git master
json.h File Reference
#include "lib/stringinfo.h"
Include dependency graph for json.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void escape_json (StringInfo buf, const char *str)
 

Function Documentation

◆ escape_json()

void escape_json ( StringInfo  buf,
const char *  str 
)

Definition at line 2463 of file json.c.

References appendStringInfo(), appendStringInfoCharMacro, and appendStringInfoString().

Referenced by composite_to_json(), datum_to_json(), escape_yaml(), ExplainDummyGroup(), ExplainOpenGroup(), ExplainProperty(), ExplainPropertyList(), ExplainPropertyListNested(), hstore_to_json(), hstore_to_json_loose(), json_object(), json_object_two_arg(), jsonb_put_escaped_value(), populate_scalar(), printJsonPathItem(), sn_object_field_start(), sn_scalar(), transform_string_values_object_field_start(), and transform_string_values_scalar().

2464 {
2465  const char *p;
2466 
2467  appendStringInfoCharMacro(buf, '"');
2468  for (p = str; *p; p++)
2469  {
2470  switch (*p)
2471  {
2472  case '\b':
2473  appendStringInfoString(buf, "\\b");
2474  break;
2475  case '\f':
2476  appendStringInfoString(buf, "\\f");
2477  break;
2478  case '\n':
2479  appendStringInfoString(buf, "\\n");
2480  break;
2481  case '\r':
2482  appendStringInfoString(buf, "\\r");
2483  break;
2484  case '\t':
2485  appendStringInfoString(buf, "\\t");
2486  break;
2487  case '"':
2488  appendStringInfoString(buf, "\\\"");
2489  break;
2490  case '\\':
2491  appendStringInfoString(buf, "\\\\");
2492  break;
2493  default:
2494  if ((unsigned char) *p < ' ')
2495  appendStringInfo(buf, "\\u%04x", (int) *p);
2496  else
2497  appendStringInfoCharMacro(buf, *p);
2498  break;
2499  }
2500  }
2501  appendStringInfoCharMacro(buf, '"');
2502 }
#define appendStringInfoCharMacro(str, ch)
Definition: stringinfo.h:127
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:163