Couchbase .NET SDK | 3.7.0
Search Results for

    Show / Hide Table of Contents

    Interface IJsonStreamReader

    Reads values and objects from a JSON stream asynchronously.

    Inherited Members
    IDisposable.Dispose()
    Namespace: Couchbase.Core.IO.Serializers
    Assembly: Couchbase.NetClient.dll
    Syntax
    public interface IJsonStreamReader : IDisposable

    Properties

    | Edit this page View Source

    Depth

    The current depth of the reader. Zero indicates ready to read the root object, one indicates an attribute on the root object, etc.

    Declaration
    int Depth { get; }
    Property Value
    Type Description
    int
    Remarks

    Example paths: "metrics" == 1, "metrics.count" == 2, "results[0].abv" == 3.

    | Edit this page View Source

    Value

    If the reader is stopped on a simple value attribute, returns the value.

    Declaration
    object? Value { get; }
    Property Value
    Type Description
    object
    | Edit this page View Source

    ValueType

    If the reader is stopped on a simple value attribute, returns the .NET type of the value. Otherwise, returns null.

    Declaration
    Type? ValueType { get; }
    Property Value
    Type Description
    Type

    Methods

    | Edit this page View Source

    InitializeAsync(CancellationToken)

    Initializes the reader

    Declaration
    Task<bool> InitializeAsync(CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    Cancellation token.

    Returns
    Type Description
    Task<bool>

    true if successfully initialized.

    Exceptions
    Type Condition
    InvalidOperationException

    InitializeAsync should only be called once.

    | Edit this page View Source

    ReadArrayAsync<T>(Func<IJsonStreamReader, CancellationToken, Task<T>>, CancellationToken)

    Reads an array of tokens at the current point in the stream.

    Declaration
    IAsyncEnumerable<T> ReadArrayAsync<T>(Func<IJsonStreamReader, CancellationToken, Task<T>> readElement, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    Func<IJsonStreamReader, CancellationToken, Task<T>> readElement

    Function which reads each element of the array.

    CancellationToken cancellationToken

    Cancellation token.

    Returns
    Type Description
    IAsyncEnumerable<T>

    An IAsyncEnumerable<T> to read the array.

    Type Parameters
    Name Description
    T

    Type of elements returned.

    | Edit this page View Source

    ReadObjectAsync<T>(CancellationToken)

    Reads an object at the current point in the stream.

    Declaration
    Task<T> ReadObjectAsync<T>(CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    Cancellation token.

    Returns
    Type Description
    Task<T>

    The object read.

    Type Parameters
    Name Description
    T

    Type of the object to read.

    Remarks

    This method also supports reading literals such as strings, numbers, nulls, etc, given the correct type for T.

    | Edit this page View Source

    ReadToNextAttributeAsync(CancellationToken)

    Reads until the next attribute is found in the stream. Returns the path to the attribute, or null if the end of the stream is reached.

    Declaration
    Task<string?> ReadToNextAttributeAsync(CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    Cancellation token.

    Returns
    Type Description
    Task<string>

    Path to the attribute relative to the overall stream, or null if the end of the stream is reached"

    Remarks

    The returned path is "." separated, and relative to the overall stream. For example, if the attribute "metrics" is on the root object, returns "metrics". If the attribute reached is "count" on the "metrics" object, the returned value is "metrics.count". Arrays are indicated with square brackets, for example "results[0].abv".

    | Edit this page View Source

    ReadTokenAsync(CancellationToken)

    Reads a dynamic token at the current point in the stream.

    Declaration
    Task<IJsonToken> ReadTokenAsync(CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    Cancellation token.

    Returns
    Type Description
    Task<IJsonToken>

    The dynamic object.

    Extension Methods

    JsonStreamDeserializerExtensions.ReadObjectsAsync<T>(IJsonStreamReader, CancellationToken)
    JsonStreamDeserializerExtensions.ReadTokensAsync(IJsonStreamReader, CancellationToken)
    • Edit this page
    • View Source
    In this article
    Back to top © 2025 Couchbase, Inc.