report_json_context(lex)));
/*
- * For UTF8, replace the escape sequence by the actual utf8
- * character in lex->strval. Do this also for other encodings
- * if the escape designates an ASCII character, otherwise
- * raise an error. We don't ever unescape a \u0000, since that
- * would result in an impermissible nul byte.
+ * For UTF8, replace the escape sequence by the actual
+ * utf8 character in lex->strval. Do this also for other
+ * encodings if the escape designates an ASCII character,
+ * otherwise raise an error. We don't ever unescape a
+ * \u0000, since that would result in an impermissible nul
+ * byte.
*/
if (ch == 0)
else if (ch <= 0x007f)
{
/*
- * This is the only way to designate things like a form feed
- * character in JSON, so it's useful in all encodings.
+ * This is the only way to designate things like a
+ * form feed character in JSON, so it's useful in all
+ * encodings.
*/
appendStringInfoChar(lex->strval, (char) ch);
}
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type json"),
- errdetail("Unicode low surrogate must follow a high surrogate."),
+ errdetail("Unicode low surrogate must follow a high surrogate."),
report_json_context(lex)));
/* Hooray, we found the end of the string! */
{
char *outputstr;
text *jsontext;
- bool numeric_error;
+ bool numeric_error;
JsonLexContext dummy_lex;
if (is_null)
break;
case TYPCATEGORY_NUMERIC:
outputstr = OidOutputFunctionCall(typoutputfunc, val);
+
/*
* Don't call escape_json here if it's a valid JSON number.
*/
dummy_lex.input = *outputstr == '-' ? outputstr + 1 : outputstr;
dummy_lex.input_length = strlen(dummy_lex.input);
json_lex_number(&dummy_lex, dummy_lex.input, &numeric_error);
- if (! numeric_error)
+ if (!numeric_error)
appendStringInfoString(result, outputstr);
else
escape_json(result, outputstr);
JsonLexContext *lex = makeJsonLexContext(json, false);
JsonTokenType tok;
- char *type;
+ char *type;
/* Lex exactly one token from the input and check its type. */
json_lex(lex);
tok = lex_peek(lex);
switch (tok)
{
- case JSON_TOKEN_OBJECT_START:
- type = "object";
- break;
- case JSON_TOKEN_ARRAY_START:
- type = "array";
- break;
- case JSON_TOKEN_STRING:
- type = "string";
- break;
- case JSON_TOKEN_NUMBER:
- type = "number";
- break;
- case JSON_TOKEN_TRUE:
- case JSON_TOKEN_FALSE:
- type = "boolean";
- break;
- case JSON_TOKEN_NULL:
- type = "null";
- break;
- default:
- elog(ERROR, "unexpected json token: %d", tok);
+ case JSON_TOKEN_OBJECT_START:
+ type = "object";
+ break;
+ case JSON_TOKEN_ARRAY_START:
+ type = "array";
+ break;
+ case JSON_TOKEN_STRING:
+ type = "string";
+ break;
+ case JSON_TOKEN_NUMBER:
+ type = "number";
+ break;
+ case JSON_TOKEN_TRUE:
+ case JSON_TOKEN_FALSE:
+ type = "boolean";
+ break;
+ case JSON_TOKEN_NULL:
+ type = "null";
+ break;
+ default:
+ elog(ERROR, "unexpected json token: %d", tok);
}
PG_RETURN_TEXT_P(cstring_to_text(type));
int result_size;
int result_count;
int sent_count;
-} OkeysState;
+} OkeysState;
/* state for json_get* functions */
typedef struct GetState
bool *pathok;
int *array_level_index;
int *path_level_index;
-} GetState;
+} GetState;
/* state for json_array_length */
typedef struct AlenState
{
JsonLexContext *lex;
int count;
-} AlenState;
+} AlenState;
/* state for json_each */
typedef struct EachState
bool normalize_results;
bool next_scalar;
char *normalized_scalar;
-} EachState;
+} EachState;
/* state for json_array_elements */
typedef struct ElementsState
TupleDesc ret_tdesc;
MemoryContext tmp_cxt;
char *result_start;
-} ElementsState;
+} ElementsState;
/* state for get_json_object_as_hash */
typedef struct JhashState
char *save_json_start;
bool use_json_as_text;
char *function_name;
-} JHashState;
+} JHashState;
/* used to build the hashtable */
typedef struct JsonHashEntry
char *val;
char *json;
bool isnull;
-} JsonHashEntry;
+} JsonHashEntry;
/* these two are stolen from hstore / record_out, used in populate_record* */
typedef struct ColumnIOData
HeapTupleHeader rec;
RecordIOData *my_extra;
MemoryContext fn_mcxt; /* used to stash IO funcs */
-} PopulateRecordsetState;
+} PopulateRecordsetState;
/*
* SQL function json_object-keys
if (!type_is_rowtype(argtype))
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("first argument of json_populate_record must be a row type")));
+ errmsg("first argument of json_populate_record must be a row type")));
if (PG_ARGISNULL(0))
{
_state->lex->token_type != JSON_TOKEN_OBJECT_START)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("must call json_populate_recordset on an array of objects")));
+ errmsg("must call json_populate_recordset on an array of objects")));
}
static void