Couchbase Lite C
Couchbase Lite C API
Functions
Converting Fleece To JSON

These are convenience functions that directly return JSON-encoded output. More...

Functions

FLStringResult FLValue_ToJSON (FLValue)
 Encodes a Fleece value as JSON (or a JSON fragment.) Any Data values will become base64-encoded JSON strings. More...
 
FLStringResult FLValue_ToJSON5 (FLValue v)
 Encodes a Fleece value as JSON5, a more lenient variant of JSON that allows dictionary keys to be unquoted if they're alphanumeric. More...
 
FLStringResult FLValue_ToJSONX (FLValue v, bool json5, bool canonicalForm)
 Most general Fleece to JSON converter. More...
 
FLStringResult FLJSON5_ToJSON (FLString json5, FLStringResult *outErrorMessage, size_t *outErrorPos, FLError *outError)
 Converts valid JSON5 https://json5.org to JSON. More...
 

Debugging Functions

const char * FLDump (FLValue)
 Debugging function that returns a C string of JSON. More...
 
const char * FLDumpData (FLSlice data)
 Debugging function that returns a C string of JSON. More...
 

Detailed Description

These are convenience functions that directly return JSON-encoded output.

For more control over the encoding, use an FLEncoder.

Function Documentation

◆ FLDump()

const char * FLDump ( FLValue  )

Debugging function that returns a C string of JSON.

Does not free the string's memory!

◆ FLDumpData()

const char * FLDumpData ( FLSlice  data)

Debugging function that returns a C string of JSON.

Does not free the string's memory!

◆ FLJSON5_ToJSON()

FLStringResult FLJSON5_ToJSON ( FLString  json5,
FLStringResult outErrorMessage,
size_t *  outErrorPos,
FLError outError 
)

Converts valid JSON5 https://json5.org to JSON.

Among other things, it converts single quotes to double, adds missing quotes around dictionary keys, removes trailing commas, and removes comments.

Note
If given invalid JSON5, it will usually return an error, but may just ouput comparably invalid JSON, in which case the caller's subsequent JSON parsing will detect the error. The types of errors it overlooks tend to be subtleties of string or number encoding.
Parameters
json5The JSON5 to parse
outErrorMessageOn failure, the error message will be stored here (if not NULL.) As this is a FLStringResult, you will be responsible for freeing it.
outErrorPosOn a parse error, the byte offset in the input where the error occurred will be stored here (if it's not NULL.)
outErrorOn failure, the error code will be stored here (if it's not NULL.)
Returns
The converted JSON.

◆ FLValue_ToJSON()

FLStringResult FLValue_ToJSON ( FLValue  )

Encodes a Fleece value as JSON (or a JSON fragment.) Any Data values will become base64-encoded JSON strings.

◆ FLValue_ToJSON5()

FLStringResult FLValue_ToJSON5 ( FLValue  v)

Encodes a Fleece value as JSON5, a more lenient variant of JSON that allows dictionary keys to be unquoted if they're alphanumeric.

This tends to be more readable.

◆ FLValue_ToJSONX()

FLStringResult FLValue_ToJSONX ( FLValue  v,
bool  json5,
bool  canonicalForm 
)

Most general Fleece to JSON converter.