Distributed Publish & Subscribe for IoT
JSON

Convert between JSON and CBOR. More...

Functions

DPS_Status DPS_CBOR2JSON (const uint8_t *cbor, size_t cborLen, char *json, size_t jsonSize, int pretty)
 Generate a JSON string from a CBOR encoded byte array. More...
 
DPS_Status DPS_JSON2CBOR (const char *json, uint8_t *cbor, size_t cborSize, size_t *cborLen)
 Generate a CBOR encoded byte array from a JSON string. More...
 

Detailed Description

Convert between JSON and CBOR.

Function Documentation

◆ DPS_CBOR2JSON()

DPS_Status DPS_CBOR2JSON ( const uint8_t *  cbor,
size_t  cborLen,
char *  json,
size_t  jsonSize,
int  pretty 
)

Generate a JSON string from a CBOR encoded byte array.

Parameters
cborCBOR encoded source data for the conversion
cborLenThe length of the CBOR data
jsonDestination buffer for generated JSON string
jsonSizeThe length of the JSON string buffer
prettyIf TRUE format the JSON using indentation and newlines, if FALSE the output is compact with no newlines or whitespace is inserted.
Returns
  • DPS_OK if the conversion was successful
  • DPS_ERR_OVERFLOW if the json buffer was too small
  • DPS_ERR_INVALID if the input was not valid CBOR
  • other error status codes

◆ DPS_JSON2CBOR()

DPS_Status DPS_JSON2CBOR ( const char *  json,
uint8_t *  cbor,
size_t  cborSize,
size_t *  cborLen 
)

Generate a CBOR encoded byte array from a JSON string.

Note that if there are multiple JSON elements in the input string only the first one is parsed and anything after the fist element is ignored.

Parameters
jsonNUL terminated JSON string to convert
cborDestination buffer for the conversion
cborSizeThe size of the cbor buffer
cborLenReturns the number of CBOR bytes written
Returns
  • DPS_OK if the conversion was successful
  • DPS_ERR_OVERFLOW if the cbor buffer was too small
  • DPS_ERR_INVALID if the input was not valid JSON
  • other error status codes