Couchbase Lite C
Couchbase Lite C API
Macros
FLJSON.h File Reference
#include "FLBase.h"

Go to the source code of this file.

Macros

#define _FLJSON_H
 

Functions

Converting to JSON

These are convenience functions that directly return a JSON representation of a value.

For more control over the encoding, use an Fleece Encoders with format kFLEncodeJSON.

FLEECE_PUBLIC FLStringResult FLValue_ToJSON (FLValue FL_NULLABLE)
 Encodes a Fleece value as JSON (or a JSON fragment.) More...
 
FLEECE_PUBLIC FLStringResult FLValue_ToJSON5 (FLValue FL_NULLABLE)
 Encodes a Fleece value as JSON5, a more lenient variant of JSON that allows dictionary keys to be unquoted if they're alphanumeric. More...
 
FLEECE_PUBLIC FLStringResult FLValue_ToJSONX (FLValue FL_NULLABLE v, bool json5, bool canonicalForm)
 Most general Fleece to JSON converter. More...
 
Parsing JSON to Fleece Values
NODISCARD FLEECE_PUBLIC FLDoc FLDoc_FromJSON (FLSlice json, FLError *FL_NULLABLE outError)
 Creates an FLDoc from JSON-encoded data. More...
 
NODISCARD FLEECE_PUBLIC FLMutableArray FL_NULLABLE FLMutableArray_NewFromJSON (FLString json, FLError *FL_NULLABLE outError)
 Creates a new mutable Array from JSON. More...
 
NODISCARD FLEECE_PUBLIC FLMutableDict FL_NULLABLE FLMutableDict_NewFromJSON (FLString json, FLError *FL_NULLABLE outError)
 Creates a new mutable Dict from json. More...
 
FLEECE_PUBLIC bool FLEncoder_ConvertJSON (FLEncoder, FLSlice json)
 Parses JSON data and writes the value(s) to the encoder as their Fleece equivalents. More...
 

Macro Definition Documentation

◆ _FLJSON_H

#define _FLJSON_H

Function Documentation

◆ FLDoc_FromJSON()

NODISCARD FLEECE_PUBLIC FLDoc FLDoc_FromJSON ( FLSlice  json,
FLError *FL_NULLABLE  outError 
)

Creates an FLDoc from JSON-encoded data.

The data is first encoded into Fleece, and the Fleece data is kept by the doc; the input JSON data is no longer needed after this function returns.

◆ FLEncoder_ConvertJSON()

FLEECE_PUBLIC bool FLEncoder_ConvertJSON ( FLEncoder  ,
FLSlice  json 
)

Parses JSON data and writes the value(s) to the encoder as their Fleece equivalents.

(This acts as a single write, like WriteInt; it's just that the value written is likely to be an entire dictionary or array.)

◆ FLMutableArray_NewFromJSON()

NODISCARD FLEECE_PUBLIC FLMutableArray FL_NULLABLE FLMutableArray_NewFromJSON ( FLString  json,
FLError *FL_NULLABLE  outError 
)

Creates a new mutable Array from JSON.

It is an error if the JSON is not an array. Its initial ref-count is 1, so a call to FLMutableArray_Release will free it.

◆ FLMutableDict_NewFromJSON()

NODISCARD FLEECE_PUBLIC FLMutableDict FL_NULLABLE FLMutableDict_NewFromJSON ( FLString  json,
FLError *FL_NULLABLE  outError 
)

Creates a new mutable Dict from json.

It is an error if the JSON is not a dictionary/object. Its initial ref-count is 1, so a call to FLMutableDict_Release will free it.

◆ FLValue_ToJSON()

FLEECE_PUBLIC FLStringResult FLValue_ToJSON ( FLValue  FL_NULLABLE)

Encodes a Fleece value as JSON (or a JSON fragment.)

Note
Any Data values will be encoded as base64-encoded strings.

◆ FLValue_ToJSON5()

FLEECE_PUBLIC FLStringResult FLValue_ToJSON5 ( FLValue  FL_NULLABLE)

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.

Note
Any Data values will be encoded as base64-encoded strings.

◆ FLValue_ToJSONX()

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

Most general Fleece to JSON converter.

Parameters
vThe Fleece value to encode
json5If true, outputs JSON5, like FLValue_ToJSON5
canonicalFormIf true, outputs the JSON in a consistent "canonical" form. All equivalent values should produce byte-for-byte identical canonical JSON. This is useful for creating digital signatures, for example.