Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JSONImpl

Implementation of JSON object.

Hierarchy

Implements

Index

Constructors

constructor

  • new JSONImpl(buffer: Uint8Array, offset?: number, length?: number): JSONImpl
  • Create a new JSONImpl instance

    Parameters

    • buffer: Uint8Array

      the internal buffer containing the JSON`

    • Default value offset: number = 0

      the offset of the data in the buffer

    • Default value length: number = buffer.length

      the number of bytes of the data in the buffer

    Returns JSONImpl

Properties

$buffer

$buffer: Uint8Array

The internal buffer

$length

$length: number

The number of bytes in the slice

$offset

$offset: number

The offset of the slice

Methods

apply

  • Apply a delta to this JSON value to create a new value.

    Convenient equivalent to: diffusion.datatypes.JSON().deltaType(delta).apply(this, delta);

    throws

    an InvalidDataError if the delta is invalid

    Parameters

    • delta: BinaryDelta

      the binary delta to apply to this value

    Returns JSON

    a new instance derived from applying the delta to this value

asArray

  • asArray(): Uint8Array
  • Get a copy of the array containing this value.

    Returns Uint8Array

    This value in binary form

asBuffer

  • asBuffer(): Buffer
  • Get a copy of the buffer containing this value.

    deprecated

    since version 6.11. Buffer has been replaced by Uint8Array. This will be removed in a future release.

    Returns Buffer

    This value in binary form

binaryDiff

  • Compare this JSON value with an earlier version to create a structural json delta.

    Convenient equivalent to: this.diff(original, 'binary');

    Standard JSON objects may also be provided as the value to diff instead of a JSON instance.

    Example:

    const delta = binaryDiff.jsonDiff({ foo : 'bar' });
    

    Parameters

    • original: any

      the value to diff against this

    Returns BinaryDeltaImpl

    a delta representing the difference between this and the provided value

copyTo

  • copyTo(target: Uint8Array, offset?: number): void
  • inheritdoc

    Parameters

    • target: Uint8Array
    • Default value offset: number = 0

    Returns void

diff

  • inheritdoc

    Parameters

    • original: any
    • type: string

    Returns JSONDeltaImpl | BinaryDeltaImpl

equalBytes

  • equalBytes(buffer: Uint8Array, offset?: number, length?: number): boolean
  • Check if the Bytes are equal to a buffer slices

    Parameters

    • buffer: Uint8Array

      the buffer

    • Default value offset: number = 0

      the offset of the slice

    • Default value length: number = buffer.length

      the number of bytes in the slice

    Returns boolean

    true if the two bytes are equal

equals

  • Check if the Bytes are equal to a buffer slices

    Parameters

    Returns boolean

    true if the two bytes are equal

get

  • get(): any
  • Get this instance's value. Use this method to access the provided data when a JSON instance is received through the API.

    Example:

    session.addStream('foo', diffusion.datatypes.json())
           .on('value', function(path, spec, value) {
        // Get the actual value from the JSON instance
        const data = value.get();
    });
    
    throws

    an InvalidDataError if the value cannot be read

    Returns any

    the JSON value

jsonDiff

  • Compare this JSON value with an earlier version to create a structural json delta.

    Convenient equivalent to: this.diff(original, 'json');

    Standard JSON objects may also be provided as the value to diff instead of a JSON instance.

    Example:

    const delta = jsonValue.jsonDiff({ foo : 'bar' });
    

    Parameters

    • original: any

      the value to diff against this

    Returns JSONDeltaImpl

    a delta representing the difference between this and the provided value

length

  • length(): number
  • Get the number of bytes

    Returns number

    The length of the data in bytes

toJsonString

  • toJsonString(): string
  • Convert the objet to a JSON string

    throws

    an InvalidDataError if the value cannot be read

    Returns string

    a JSON string representation of the JSON object

toString

  • toString(): string
  • Convert the objet to a string

    throws

    an InvalidDataError if the value cannot be read

    Returns string

    a string representation of the JSONImpl

Static from

  • Create a new JSON object from a raw object or a RecordV2Impl. If a RecordV2Impl is passed as argument it is simply returned.

    Parameters

    • value: any

      the object to create a JSON from

    Returns JSONImpl

    the JSON created

Static toString

  • toString(): string
  • Return the name of the data type

    Returns string

    JSONImpl

Copyright © 2025 DiffusionData Ltd. All Rights Reserved.