cjson

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2025 License: Apache-2.0 Imports: 2 Imported by: 7

Documentation

Index

Constants

View Source
const IsReference = 256
View Source
const LLGoPackage string = "link: $(pkg-config --libs libcjson libcjson_utils);"
View Source
const NESTING_LIMIT = 1000
View Source
const StringIsConst = 512
View Source
const VERSION_MAJOR = 1
View Source
const VERSION_MINOR = 7
View Source
const VERSION_PATCH = 18

Variables

This section is empty.

Functions

func FreeCStr

func FreeCStr(object c.Pointer)

func GetErrorPtr

func GetErrorPtr() *c.Char

For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds.

func Malloc

func Malloc(size c.SizeT) c.Pointer

malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks

func Minify

func Minify(json *c.Char)

Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. * The input pointer json cannot point to a read-only address area, such as a string constant, * but should point to a readable and writable address area.

func Version

func Version() *c.Char

returns the version of cJSON as a string

Types

type Bool

type Bool c.Int

type Hooks

type Hooks struct {
	MallocFn c.Pointer
	FreeFn   c.Pointer
}

func (*Hooks) InitHooks

func (recv_ *Hooks) InitHooks()
Supply malloc, realloc and free functions to cJSON

llgo:link (*Hooks).InitHooks C.cJSON_InitHooks

type JSON

type JSON struct {
	Next        *JSON
	Prev        *JSON
	Child       *JSON
	Type        c.Int
	Valuestring *c.Char
	Valueint    c.Int
	Valuedouble c.Double
	String      *c.Char
}

func Array

func Array() *JSON

func CreateBool

func CreateBool(boolean Bool) *JSON

func DoubleArray

func DoubleArray(numbers *c.Double, count c.Int) *JSON

func False

func False() *JSON

func FloatArray

func FloatArray(numbers *c.Float, count c.Int) *JSON

func IntArray

func IntArray(numbers *c.Int, count c.Int) *JSON

These utilities create an Array of count items. * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.

func Null

func Null() *JSON

These calls create a cJSON item of the appropriate type.

func Number

func Number(num c.Double) *JSON

func Object

func Object() *JSON

func ObjectRef

func ObjectRef(child *JSON) *JSON

Create an object/array that only references it's elements so * they will not be freed by cJSON_Delete

func Parse

func Parse(value *c.Char) *JSON

Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. Supply a block of JSON, and this returns a cJSON object you can interrogate.

func ParseWithLength

func ParseWithLength(value *c.Char, buffer_length c.SizeT) *JSON

func ParseWithLengthOpts

func ParseWithLengthOpts(value *c.Char, buffer_length c.SizeT, return_parse_end **c.Char, require_null_terminated Bool) *JSON

func ParseWithOpts

func ParseWithOpts(value *c.Char, return_parse_end **c.Char, require_null_terminated Bool) *JSON

ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr().

func Raw

func Raw(raw *c.Char) *JSON

raw json

func String

func String(string *c.Char) *JSON

func StringArray

func StringArray(strings **c.Char, count c.Int) *JSON

func StringRef

func StringRef(string *c.Char) *JSON

Create a string where valuestring references a string so * it will not be freed by cJSON_Delete

func True

func True() *JSON

func (*JSON) AddArrayToObject

func (recv_ *JSON) AddArrayToObject(name *c.Char) *JSON

llgo:link (*JSON).AddArrayToObject C.cJSON_AddArrayToObject

func (*JSON) AddBoolToObject

func (recv_ *JSON) AddBoolToObject(name *c.Char, boolean Bool) *JSON

llgo:link (*JSON).AddBoolToObject C.cJSON_AddBoolToObject

func (*JSON) AddFalseToObject

func (recv_ *JSON) AddFalseToObject(name *c.Char) *JSON

llgo:link (*JSON).AddFalseToObject C.cJSON_AddFalseToObject

func (*JSON) AddItem

func (recv_ *JSON) AddItem(item *JSON) Bool
Append item to the specified array/object.

llgo:link (*JSON).AddItem C.cJSON_AddItemToArray

func (*JSON) AddItemReferenceToArray

func (recv_ *JSON) AddItemReferenceToArray(item *JSON) Bool
Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON.

llgo:link (*JSON).AddItemReferenceToArray C.cJSON_AddItemReferenceToArray

func (*JSON) AddItemReferenceToObject

func (recv_ *JSON) AddItemReferenceToObject(string *c.Char, item *JSON) Bool

llgo:link (*JSON).AddItemReferenceToObject C.cJSON_AddItemReferenceToObject

func (*JSON) AddItemToObjectCS

func (recv_ *JSON) AddItemToObjectCS(string *c.Char, item *JSON) Bool
Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string`

llgo:link (*JSON).AddItemToObjectCS C.cJSON_AddItemToObjectCS

func (*JSON) AddNullToObject

func (recv_ *JSON) AddNullToObject(name *c.Char) *JSON
Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure.

llgo:link (*JSON).AddNullToObject C.cJSON_AddNullToObject

func (*JSON) AddNumberToObject

func (recv_ *JSON) AddNumberToObject(name *c.Char, number c.Double) *JSON

llgo:link (*JSON).AddNumberToObject C.cJSON_AddNumberToObject

func (*JSON) AddObjectToObject

func (recv_ *JSON) AddObjectToObject(name *c.Char) *JSON

llgo:link (*JSON).AddObjectToObject C.cJSON_AddObjectToObject

func (*JSON) AddPatchToArray

func (recv_ *JSON) AddPatchToArray(operation *c.Char, path *c.Char, value *JSON)
Utility for generating patch array entries.

llgo:link (*JSON).AddPatchToArray C.cJSONUtils_AddPatchToArray

func (*JSON) AddRawToObject

func (recv_ *JSON) AddRawToObject(name *c.Char, raw *c.Char) *JSON

llgo:link (*JSON).AddRawToObject C.cJSON_AddRawToObject

func (*JSON) AddStringToObject

func (recv_ *JSON) AddStringToObject(name *c.Char, string *c.Char) *JSON

llgo:link (*JSON).AddStringToObject C.cJSON_AddStringToObject

func (*JSON) AddTrueToObject

func (recv_ *JSON) AddTrueToObject(name *c.Char) *JSON

llgo:link (*JSON).AddTrueToObject C.cJSON_AddTrueToObject

func (*JSON) ApplyPatches

func (recv_ *JSON) ApplyPatches(patches *JSON) c.Int
Returns 0 for success.

llgo:link (*JSON).ApplyPatches C.cJSONUtils_ApplyPatches

func (*JSON) ApplyPatchesCaseSensitive

func (recv_ *JSON) ApplyPatchesCaseSensitive(patches *JSON) c.Int

llgo:link (*JSON).ApplyPatchesCaseSensitive C.cJSONUtils_ApplyPatchesCaseSensitive

func (*JSON) CStr

func (recv_ *JSON) CStr() *c.Char
Render a cJSON entity to text for transfer/storage without any formatting.

llgo:link (*JSON).CStr C.cJSON_PrintUnformatted

func (*JSON) Compare

func (recv_ *JSON) Compare(b *JSON, case_sensitive Bool) Bool
Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate.
Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0)

llgo:link (*JSON).Compare C.cJSON_Compare

func (*JSON) CreateArrayRef

func (recv_ *JSON) CreateArrayRef() *JSON

llgo:link (*JSON).CreateArrayRef C.cJSON_CreateArrayReference

func (*JSON) Delete

func (recv_ *JSON) Delete()
Delete a cJSON entity and all subentities.

llgo:link (*JSON).Delete C.cJSON_Delete

func (*JSON) DeleteItemFromArray

func (recv_ *JSON) DeleteItemFromArray(which c.Int)

llgo:link (*JSON).DeleteItemFromArray C.cJSON_DeleteItemFromArray

func (*JSON) DeleteItemFromObject

func (recv_ *JSON) DeleteItemFromObject(string *c.Char)

llgo:link (*JSON).DeleteItemFromObject C.cJSON_DeleteItemFromObject

func (*JSON) DeleteItemFromObjectCaseSensitive

func (recv_ *JSON) DeleteItemFromObjectCaseSensitive(string *c.Char)

llgo:link (*JSON).DeleteItemFromObjectCaseSensitive C.cJSON_DeleteItemFromObjectCaseSensitive

func (*JSON) DetachItemFromArray

func (recv_ *JSON) DetachItemFromArray(which c.Int) *JSON

llgo:link (*JSON).DetachItemFromArray C.cJSON_DetachItemFromArray

func (*JSON) DetachItemFromObject

func (recv_ *JSON) DetachItemFromObject(string *c.Char) *JSON

llgo:link (*JSON).DetachItemFromObject C.cJSON_DetachItemFromObject

func (*JSON) DetachItemFromObjectCaseSensitive

func (recv_ *JSON) DetachItemFromObjectCaseSensitive(string *c.Char) *JSON

llgo:link (*JSON).DetachItemFromObjectCaseSensitive C.cJSON_DetachItemFromObjectCaseSensitive

func (*JSON) DetachItemViaPointer

func (recv_ *JSON) DetachItemViaPointer(item *JSON) *JSON
Remove/Detach items from Arrays/Objects.

llgo:link (*JSON).DetachItemViaPointer C.cJSON_DetachItemViaPointer

func (*JSON) Duplicate

func (recv_ *JSON) Duplicate(recurse Bool) *JSON
Duplicate a cJSON item

llgo:link (*JSON).Duplicate C.cJSON_Duplicate

func (*JSON) FindPointerFromObjectTo

func (recv_ *JSON) FindPointerFromObjectTo(target *JSON) *c.Char
Given a root object and a target object, construct a pointer from one to the other.

llgo:link (*JSON).FindPointerFromObjectTo C.cJSONUtils_FindPointerFromObjectTo

func (*JSON) GenerateMergePatch

func (recv_ *JSON) GenerateMergePatch(to *JSON) *JSON
generates a patch to move from -> to
NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key

llgo:link (*JSON).GenerateMergePatch C.cJSONUtils_GenerateMergePatch

func (*JSON) GenerateMergePatchCaseSensitive

func (recv_ *JSON) GenerateMergePatchCaseSensitive(to *JSON) *JSON

llgo:link (*JSON).GenerateMergePatchCaseSensitive C.cJSONUtils_GenerateMergePatchCaseSensitive

func (*JSON) GeneratePatches

func (recv_ *JSON) GeneratePatches(to *JSON) *JSON
Implement RFC6902 (https://tools.ietf.org/html/rfc6902) JSON Patch spec.
NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key

llgo:link (*JSON).GeneratePatches C.cJSONUtils_GeneratePatches

func (*JSON) GeneratePatchesCaseSensitive

func (recv_ *JSON) GeneratePatchesCaseSensitive(to *JSON) *JSON

llgo:link (*JSON).GeneratePatchesCaseSensitive C.cJSONUtils_GeneratePatchesCaseSensitive

func (*JSON) GetArrayItem

func (recv_ *JSON) GetArrayItem(index c.Int) *JSON
Retrieve item number "index" from array "array". Returns NULL if unsuccessful.

llgo:link (*JSON).GetArrayItem C.cJSON_GetArrayItem

func (*JSON) GetArraySize

func (recv_ *JSON) GetArraySize() c.Int
Returns the number of items in an array (or object).

llgo:link (*JSON).GetArraySize C.cJSON_GetArraySize

func (*JSON) GetNumberValue

func (recv_ *JSON) GetNumberValue() c.Double

llgo:link (*JSON).GetNumberValue C.cJSON_GetNumberValue

func (*JSON) GetObjectItem

func (recv_ *JSON) GetObjectItem(string *c.Char) *JSON
Get item "string" from object. Case insensitive.

llgo:link (*JSON).GetObjectItem C.cJSON_GetObjectItem

func (*JSON) GetObjectItemCaseSensitive

func (recv_ *JSON) GetObjectItemCaseSensitive(string *c.Char) *JSON

llgo:link (*JSON).GetObjectItemCaseSensitive C.cJSON_GetObjectItemCaseSensitive

func (*JSON) GetPointer

func (recv_ *JSON) GetPointer(pointer *c.Char) *JSON
Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec.

llgo:link (*JSON).GetPointer C.cJSONUtils_GetPointer

func (*JSON) GetPointerCaseSensitive

func (recv_ *JSON) GetPointerCaseSensitive(pointer *c.Char) *JSON

llgo:link (*JSON).GetPointerCaseSensitive C.cJSONUtils_GetPointerCaseSensitive

func (*JSON) GetStringValue

func (recv_ *JSON) GetStringValue() *c.Char
Check item type and return its value

llgo:link (*JSON).GetStringValue C.cJSON_GetStringValue

func (*JSON) HasObjectItem

func (recv_ *JSON) HasObjectItem(string *c.Char) Bool

llgo:link (*JSON).HasObjectItem C.cJSON_HasObjectItem

func (*JSON) InsertItemInArray

func (recv_ *JSON) InsertItemInArray(which c.Int, newitem *JSON) Bool
Update array items.

llgo:link (*JSON).InsertItemInArray C.cJSON_InsertItemInArray

func (*JSON) IsArray

func (recv_ *JSON) IsArray() Bool

llgo:link (*JSON).IsArray C.cJSON_IsArray

func (*JSON) IsBool

func (recv_ *JSON) IsBool() Bool

llgo:link (*JSON).IsBool C.cJSON_IsBool

func (*JSON) IsFalse

func (recv_ *JSON) IsFalse() Bool

llgo:link (*JSON).IsFalse C.cJSON_IsFalse

func (*JSON) IsInvalid

func (recv_ *JSON) IsInvalid() Bool
These functions check the type of an item

llgo:link (*JSON).IsInvalid C.cJSON_IsInvalid

func (*JSON) IsNull

func (recv_ *JSON) IsNull() Bool

llgo:link (*JSON).IsNull C.cJSON_IsNull

func (*JSON) IsNumber

func (recv_ *JSON) IsNumber() Bool

llgo:link (*JSON).IsNumber C.cJSON_IsNumber

func (*JSON) IsObject

func (recv_ *JSON) IsObject() Bool

llgo:link (*JSON).IsObject C.cJSON_IsObject

func (*JSON) IsRaw

func (recv_ *JSON) IsRaw() Bool

llgo:link (*JSON).IsRaw C.cJSON_IsRaw

func (*JSON) IsString

func (recv_ *JSON) IsString() Bool

llgo:link (*JSON).IsString C.cJSON_IsString

func (*JSON) IsTrue

func (recv_ *JSON) IsTrue() Bool

llgo:link (*JSON).IsTrue C.cJSON_IsTrue

func (*JSON) MergePatch

func (recv_ *JSON) MergePatch(patch *JSON) *JSON
Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec.
target will be modified by patch. return value is new ptr for target.

llgo:link (*JSON).MergePatch C.cJSONUtils_MergePatch

func (*JSON) MergePatchCaseSensitive

func (recv_ *JSON) MergePatchCaseSensitive(patch *JSON) *JSON

llgo:link (*JSON).MergePatchCaseSensitive C.cJSONUtils_MergePatchCaseSensitive

func (*JSON) Print

func (recv_ *JSON) Print() *c.Char
Render a cJSON entity to text for transfer/storage.

llgo:link (*JSON).Print C.cJSON_Print

func (*JSON) PrintBuffered

func (recv_ *JSON) PrintBuffered(prebuffer c.Int, fmt Bool) *c.Char
Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted

llgo:link (*JSON).PrintBuffered C.cJSON_PrintBuffered

func (*JSON) PrintPreallocated

func (recv_ *JSON) PrintPreallocated(buffer *c.Char, length c.Int, format Bool) Bool
Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure.
NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need

llgo:link (*JSON).PrintPreallocated C.cJSON_PrintPreallocated

func (*JSON) ReplaceItemInArray

func (recv_ *JSON) ReplaceItemInArray(which c.Int, newitem *JSON) Bool

llgo:link (*JSON).ReplaceItemInArray C.cJSON_ReplaceItemInArray

func (*JSON) ReplaceItemInObject

func (recv_ *JSON) ReplaceItemInObject(string *c.Char, newitem *JSON) Bool

llgo:link (*JSON).ReplaceItemInObject C.cJSON_ReplaceItemInObject

func (*JSON) ReplaceItemInObjectCaseSensitive

func (recv_ *JSON) ReplaceItemInObjectCaseSensitive(string *c.Char, newitem *JSON) Bool

llgo:link (*JSON).ReplaceItemInObjectCaseSensitive C.cJSON_ReplaceItemInObjectCaseSensitive

func (*JSON) ReplaceItemViaPointer

func (recv_ *JSON) ReplaceItemViaPointer(item *JSON, replacement *JSON) Bool

llgo:link (*JSON).ReplaceItemViaPointer C.cJSON_ReplaceItemViaPointer

func (*JSON) SetItem

func (recv_ *JSON) SetItem(string *c.Char, item *JSON) Bool

llgo:link (*JSON).SetItem C.cJSON_AddItemToObject

func (*JSON) SetNumberHelper

func (recv_ *JSON) SetNumberHelper(number c.Double) c.Double
helper for the cJSON_SetNumberValue macro

llgo:link (*JSON).SetNumberHelper C.cJSON_SetNumberHelper

func (*JSON) SetValuestring

func (recv_ *JSON) SetValuestring(valuestring *c.Char) *c.Char
Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String

llgo:link (*JSON).SetValuestring C.cJSON_SetValuestring

func (*JSON) SortObject

func (recv_ *JSON) SortObject()
Sorts the members of the object into alphabetical order.

llgo:link (*JSON).SortObject C.cJSONUtils_SortObject

func (*JSON) SortObjectCaseSensitive

func (recv_ *JSON) SortObjectCaseSensitive()

llgo:link (*JSON).SortObjectCaseSensitive C.cJSONUtils_SortObjectCaseSensitive

Directories

Path Synopsis
_demo
hello command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL