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 2483 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().

2484 {
2485  const char *p;
2486 
2487  appendStringInfoCharMacro(buf, '"');
2488  for (p = str; *p; p++)
2489  {
2490  switch (*p)
2491  {
2492  case '\b':
2493  appendStringInfoString(buf, "\\b");
2494  break;
2495  case '\f':
2496  appendStringInfoString(buf, "\\f");
2497  break;
2498  case '\n':
2499  appendStringInfoString(buf, "\\n");
2500  break;
2501  case '\r':
2502  appendStringInfoString(buf, "\\r");
2503  break;
2504  case '\t':
2505  appendStringInfoString(buf, "\\t");
2506  break;
2507  case '"':
2508  appendStringInfoString(buf, "\\\"");
2509  break;
2510  case '\\':
2511  appendStringInfoString(buf, "\\\\");
2512  break;
2513  default:
2514  if ((unsigned char) *p < ' ')
2515  appendStringInfo(buf, "\\u%04x", (int) *p);
2516  else
2517  appendStringInfoCharMacro(buf, *p);
2518  break;
2519  }
2520  }
2521  appendStringInfoCharMacro(buf, '"');
2522 }
#define appendStringInfoCharMacro(str, ch)
Definition: stringinfo.h:128
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176