Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Rename JsonNode and related types to JTreeNode, move them to S.T.Json.Linq namespace, and address partial usability feedback - #41128

Closed
ahsonkhan wants to merge 17 commits into
dotnet:masterfrom
ahsonkhan:JsonNodeRename
Closed

ahsonkhan wants to merge 17 commits into
dotnet:masterfrom
ahsonkhan:JsonNodeRename

Conversation

@ahsonkhan

@ahsonkhan ahsonkhan commented Sep 16, 2019 •

Copy link
Copy Markdown

Forked from #41030 (and hence depends on it).

Changes:

  • Move JsonNode and related types to S.T.Json.Linq namespace.
  • Rename JsonNode and related types to JNode, JObject, etc. Rename JsonNode and related types to JTreeNode, JTreeObject, etc.
  • Add JObject.Parse and JArray.Parse.
  • Override JNode.ToString to return the JSON string representation.
  • Modify some of the xml comments to improve JNode discoverability.
  • Rename GetNode to GetOriginatingNode to make it less inviting.
  • Add instance method JsonElement.ToJNode which does the deep copy.
  • Move the JArray and JObject enumerators as nested types.

Should we wait for this PR to get merged until after #41041?

This PR isn't ready to be merged until more tests are added but a review would help.
Very few changes are made to the implementation details. It's probably easiest to review this one commit at a time.

cc @kasiabulat, @terrajobst, @bartonjs, @joperezr

@ahsonkhan ahsonkhan added * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) area-System.Text.Json labels Sep 16, 2019
@ahsonkhan ahsonkhan added this to the 5.0 milestone Sep 16, 2019
}

/// <summary>
/// Parses a string representing JSON document into a <see cref="JArray"/>.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should change the word "document" in JNode.Parse (and JObject.Parse and JArray.Parse) documentation, so that users won't associate it with JsonDocument?

{
/// <summary>
/// The base class that represents a single node within a mutable JSON document.
/// The base class that represents a single node within a mutable JSON document. See also <see cref="JObject"/> and <see cref="JArray"/> which derive from <see cref="JNode"/>.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add references to JNode in JsonDocument documentation, maybe it would be worth mentioning JsonDocument in JNode documentation as well?

@kasiabulat kasiabulat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@kasiabulat

Copy link
Copy Markdown
Contributor

Should we wait for this PR to get merged until after #41041?

Maybe it would be better to separate UX study feedback from actual fixes, so I think we should merge my PR first and then this one (with perhaps some more changes after the second day of study results). However, I am not sure when I will be able to address review comments to my PR.

public uint GetUInt32() { throw null; }
[System.CLSCompliantAttribute(false)]
public ulong GetUInt64() { throw null; }
public System.Text.Json.Linq.JNode ToJNode() { throw null; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@davidfowl

Copy link
Copy Markdown
Member

What's the intent here on using the exact same names as JSON.NET? Aren't we worried about type conflicts?

@joperezr

Copy link
Copy Markdown
Member

the intent here was to do a separation of concepts between JsonDocument and JsonElement and the modifiable types for the writable DOM. It might very well be that using the same names as JSON.NET is not the right plan, as it might cause confusion for web searches or stack overflow, but we are currently experimenting and performing UX Studies to see what the right design is.

/// Represents a mutable JSON object.
/// </summary>
public sealed class JsonObject : JsonNode, IEnumerable<KeyValuePair<string, JsonNode>>
public sealed partial class JObject : JNode, IEnumerable<KeyValuePair<string, JNode>>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally support a rename and a new namespace, but I don't think that in general clashing with Json.NET is a good idea.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The renaming uniforms System.Text.Json.Linq with System.Xml.Linq which uses X prefixes instead of Xml (:

@davidfowl

Copy link
Copy Markdown
Member

t might very well be that using the same names as JSON.NET is not the right plan, as it might cause confusion for web searches or stack overflow, but we are currently experimenting and performing UX Studies to see what the right design is.

Pretty sure this isn't a great idea. I don't see how this is viable. Applications will pull in both for the foreseeable future (transitively or directly) and it'll clash.

@joperezr

Copy link
Copy Markdown
Member

That could still be worked around though, by using aliases or such. That said, I agree with you that I don't feel that having the name clashing is a good idea. I believe that for now we are prototyping different alternatives and see how users react to it, although @ahsonkhan could correct me if that is not the case.

@davidfowl

Copy link
Copy Markdown
Member

That could still be worked around though, by using aliases or such.

That's user hostile though.

{
IEnumerator enumerator = _enumerator;
enumerator.Reset();
_enumerator = (List<JNode>.Enumerator)enumerator;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid allocation here via a devirtualization trick:

void IEnumerator.Reset() => ResetCore(_enumerator);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void ResetCore<T>(in T enumerator)
    where T : struct, IEnumerator
    => enumerator.Reset();
JArray+Enumerator.System.Collections.IEnumerator.Reset()
    L0000: push ebp
    L0001: mov ebp, esp
    L0003: push eax
    L0004: mov [ebp-0x4], ecx
    L0007: cmp dword [0x1c30c1a8], 0x0
    L000e: jz L0015
    L0010: call 0x62f15b90
    L0015: nop
    L0016: mov ecx, [ebp-0x4]
    L0019: call dword [0x1c30cd14]
    L001f: nop
    L0020: nop
    L0021: mov esp, ebp
    L0023: pop ebp
    L0024: ret

@maryamariyan

maryamariyan commented Nov 6, 2019 •

Copy link
Copy Markdown

Thank you for your contribution. As announced in dotnet/coreclr#27549 this repository will be moving to dotnet/runtime on November 13. If you would like to continue working on this PR after this date, the easiest way to move the change to dotnet/runtime is:

  1. In your corefx repository clone, create patch by running git format-patch origin
  2. In your runtime repository clone, apply the patch by running git apply --directory src/libraries <path to the patch created in step 1>

@joperezr

Copy link
Copy Markdown
Member

@ahsonkhan I suppose this one we want to close?

@ahsonkhan ahsonkhan removed the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Nov 13, 2019
@ahsonkhan ahsonkhan added the post-consolidation PRs which will be hand ported to dotnet/runtime label Nov 13, 2019
set
{
_list[idx] = value ?? new JsonNull();
_list[idx] = value ?? new JTreeNull();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't there just a change to use a singleton of null?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, in the refactoring PR. Waiting for that one to get merged first, and then will update this PR. This PR won't make it, so I will port it manually to the other repo.

@ahsonkhan ahsonkhan changed the title Rename JsonNode and related types to JNode, move them to S.T.Json.Linq namespace, and address partial usability feedback Rename JsonNode and related types to JTreeNode, move them to S.T.Json.Linq namespace, and address partial usability feedback Nov 13, 2019
@ViktorHofer ViktorHofer added the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Nov 14, 2019
@maryamariyan

Copy link
Copy Markdown

Thank you for your contribution. As announced in #27549 the dotnet/runtime repository will be used going forward for changes to this code base. Closing this PR as no more changes will be accepted into master for this repository. If you’d like to continue working on this change please move it to dotnet/runtime.

@maryamariyan maryamariyan removed this from the 5.0 milestone Dec 2, 2019
@joperezr

joperezr commented Dec 9, 2019

Copy link
Copy Markdown
Member

@ahsonkhan do you plan on moving this one over there? We did add the post-consolidation tag so I thought this wouldn't get closed, but let's just make sure that this work eventually happens.

@ahsonkhan

Copy link
Copy Markdown
Author

do you plan on moving this one over there? We did add the post-consolidation tag so I thought this wouldn't get closed, but let's just make sure that this work eventually happens.

I am focused on some other things atm, but yes, I plan to open this up in dotnet/runtime soon (maybe next week). Thanks for the reminder.
If anyone else wants to take this forward, please feel free to do so :)

@karelz karelz added this to the 5.0 milestone Dec 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Text.Json * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) post-consolidation PRs which will be hand ported to dotnet/runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants