Skip to content

Conversation

@sakuntalle
Copy link

@sakuntalle sakuntalle commented Oct 30, 2025

With version 3.12.0 the underlying type for a nlohmann::json object has become nlohmann::json_abi_diag_v3_12_0::detail::json_default_base and this type does not have a Type definition in the corresponding natvis template and generated natvis file.

This PR updates the Natvis jinja template to add all the types derived from json_default_base. Also the template is rendered to produce the nlohmann_json.natvis

fixes #4972

  • The changes are described in detail, both the what and why.
  • If applicable, an existing issue is referenced.
  • The Code coverage remained at 100%. A test case for every new line of code.
  • If applicable, the documentation is updated.
  • The source code is amalgamated by running make amalgamate.

Read the Contribution Guidelines for detailed information.

@sakuntalle sakuntalle requested a review from nlohmann as a code owner October 30, 2025 08:33
@github-actions github-actions bot added the L label Oct 30, 2025
@coveralls
Copy link

coveralls commented Oct 30, 2025

Coverage Status

coverage: 99.191%. remained the same
when pulling 78ede22 on sakuntalle:develop
into a6a92c1 on nlohmann:develop.

@nlohmann nlohmann added the review needed It would be great if someone could review the proposed changes. label Oct 30, 2025
</Type>

<Type Name="{{ ns }}::detail::json_default_base">
<DisplayString Condition="m_data.m_type == {{ ns }}::detail::value_t::null">null</DisplayString>
Copy link
Contributor

Choose a reason for hiding this comment

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

m_data is not a member of json_default_base. Why is this useful?

Copy link
Author

Choose a reason for hiding this comment

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

Hey Greg!
I understand your concern and I'll have to admit I'm not versed into the library internal data structures.
But what I did notice with the VS version added in the linked issue can be seen in this screenshot
image

So VS sees the nlohmann:json object obj type as a json default_base object which most likely is just a polymorphic type. That's probably the reason why m_data can be found in the object.
And after I've added the natvis type I was suggesting in this PR VS did manage to show properly the content of it as in the screenshot below

image

Copy link
Contributor

Choose a reason for hiding this comment

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

That's interesting. What is json_t?

Copy link
Author

Choose a reason for hiding this comment

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

oh yeah, sorry, that's just a typedef to nlohmann::json we use in our codebase

Copy link
Author

Choose a reason for hiding this comment

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

Hey guys,

I've dig deeper into this situation and I've learned the followings:
In Visual Studio 2022, when inspecting nlohmann::json variables, the debugger often shows them as the empty base type nlohmann::detail::json_default_base. This happens because VS displays objects according to their static type, not their dynamic type — even though the runtime object is a full nlohmann::json.
Without a visualizer for json_default_base, the debugger cannot interpret the derived JSON contents and only shows raw memory or {...}.

Adding a Natvis for json_default_base ensures that the debugger displays JSON values based on their actual type (object, array, string, etc.) and allows convenient expansion. Although json_default_base is empty in C++, this visualizer is required to bridge the gap between VS’s static-type view and the actual runtime data.

I've tried a few workarounds to make it take the dynamic type instead but I failed to produce a working natvis file.
Maybe somebody with more Natvis experience would be able to crack this, I dunno :)

Copy link
Contributor

Choose a reason for hiding this comment

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

That's definitely not their static type, because if that were their static type, you wouldn't be able to do anything with them. The static type of obj is nlohmann::json. I wonder if it's being confused by the inline namespace or the alias, and that's what it's looking up in natvis. It is finding the base type, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L review needed It would be great if someone could review the proposed changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Natvis file for version 3.12.0 does not contain a type definition for detail::json_default_base

4 participants