Skip to content

Expose the current context / scope as a property from the Utf8JsonReader. #1557

Closed

Description

@ahsonkhan

Split off from https://github.com/dotnet/corefx/issues/33967.
The JSON Document requires the concept of in object or in array which the JsonReader tracks and will be made internal to support the document. Should we expose it publically so the caller doesn't have to build their own stack to track this while reading?

https://github.com/dotnet/corefx/blob/c30f2bc75066aeccd610f36c8ce84ae5aaff675a/src/System.Text.Json/src/System/Text/Json/Utf8JsonReader.cs#L31

The other internal detail that the document object needed is InArray, but that can be worked around by the caller maintaining their own Stack<JsonTokenType>.

namespace System.Text.Json
{
    public ref partial struct Utf8JsonReader
    {
        public JsonContext Context { get; }
        // OR one (or both) of these
        public bool InObject { get; }
        public bool InArray { get; }
    }

    // OR Scope?
    // Can't call it state, since we already have such a concept and overloading it would be confusing
    public enum JsonContext : byte
    {
        Object,
        Array,
        None,
        Value, // Remove? OR split into specific JSON primitives, like String, Number, etc.?
    }
}

cc @bartonjs

Activity

  1. self-assigned this
    on Jan 17, 2019
  2. removed their assignment
    on Jan 24, 2019
  3. transferred this issue fromdotnet/corefxon Jan 9, 2020
  4. removed
    untriagedNew issue has not been triaged by the area owner
    on Feb 20, 2020
  5. added this to the Future milestone on Feb 20, 2020
  6. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Feb 20, 2020
  7. ghost closed this as completedon Nov 5, 2021
  8. ghost locked as resolved and limited conversation to collaborators on Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.Jsonbacklog-cleanup-candidateAn inactive issue that has been marked for automated closure.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions