Newtonsoft Json package

So now that Unity has brought in Newtonsoft.Json.dll in their own package, the docs say:
“To avoid assembly clashes, please use this package if you intend to use Newtonsoft Json.”

But the docs for the package say:
"This is a package intended for internal Unity Development Projects and as such this package is not supported. Use at your own risk."

So is this package going to be supported now that we’re forced to use it?

(Also it’s spelt wrong on Newtonsoft Json Unity Package | Newtonsoft Json | 2.0.2)

I should note that I’m using Unity 2019.3.4f1 but it seems the package is for 2020?

5 Likes

Where does it say you’re forced to use it? I use newtonsoft json quite a bit, but I’ve either used the one on the asset store or lately I’ve switched to this one GitHub - applejag/Newtonsoft.Json-for-Unity: Newtonsoft.Json (Json.NET) 10.0.3, 11.0.2, 12.0.3, & 13.0.1 for Unity IL2CPP builds, available via Unity Package Manager which is being updated.

1 Like

It’s a new package (com.unity.nuget.newtonsoft-json) which is a dependency of Platforms (com.unity.platforms@0.2) which is a dependency of Entities (com.unity.entities@0.7)

3 Likes

It’s a bit uncouth of Unity to force their own version of Newtonsoft Json as a dependency.

It’s pretty easy to keep using your own version though:

  • Move the “com.unity.platforms” package from Library/PackageCache to your Packages folder
  • Remove “com.unity.nuget.newtonsoft-json”: “1.1.2” from its dependencies in package.json
8 Likes

What do you mean doesn’t support IL2CPP? I haven’t noticed any problems with it.

I did encounter this unhelpful error in build after trying Unity’s version : currently not available on il2cpp Line: -1

I’ve seen this before when trying to use Newtonsoft’s Json with AOT compilation.
I didn’t bother investigating too deeply what exactly was missing, and reverted back to https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347
If you didn’t encounter any issues, it might actually be fine for most use cases, I’ve edited my post above.

@multivac you were right, versions previous to 2.0-preview don’t work with IL2CPP, which is pretty crazy.

But now the package we have to use is a preview and internal package?

@ package developers, please resolve this.

5 Likes

Hi all,

I’m sorry that you all have been experiencing issues with the com.unity.nuget.newtonsoft-json package. I am one of the developers that developed the initial package. Firstly, I’d like to provide some context as to why the package was introduced in the first place. I assume that we are all aware that Unity does not handle strong named assemblies (Strong-named assemblies - .NET | Microsoft Learn). This means that there can only be one copy of a specific assembly on a system, which is an issue when both packages and users may introduce their own copies of some popular library. Newtonsoft Json is one of these. This lead to the decision to create a package to serve as a common ground for other Unity packages.
The package is marked as not supported because we don’t want users to expect a level of support on par to an official Unity package. The package is supported and we will fix some Unity specific issues, but any issues with Newtonsoft Json itself should be directed back to the developers of the library.
In no way are we taking away choice from the user. In fact by making this package a common dependency, users can use the local package override to override the newtonsoft json version for everything. Simply copy the package into your packages directory and replace the dll and the AOT dll. The link.xml file can also be modified to your needs. However, keep in mind that any change comes with the risk of breaking things.
As of version 2, we have IL2CPP support similar to the one here GitHub - applejag/Newtonsoft.Json-for-Unity: Newtonsoft.Json (Json.NET) 10.0.3, 11.0.2, 12.0.3, & 13.0.1 for Unity IL2CPP builds, available via Unity Package Manager
Version 2 will be out of preview soon with support for all Unity platforms. I believe it’s using the latest version of newtonsoft json.

The spelling mistake has been fixed and will be included in the next update!

11 Likes

@christophera_unity I have no problem with Unity providing the library (I certainly wouldn’t want different copies in my project), but I do have a problem with it being labelled as unsupported and internal. You know people are going to have to put in considerable effort to remove/replace it - not to mention that Unity packages would then be relying on an external json package, surely you aren’t going to say that’s a supported scenario.

What I would like to see:

  • Remove the “unsupported” and “internal use” and “use at own risk” texts and replace it with a more friendly reminder that it’s a third party library.
  • Since you have made source changes for the AOT version, make the source available online so people can see it and contribute issues/fixes - again you can have some indication here it’s a third party dll, but now we are relying on Unity for updates from the original package.
2 Likes

@SLGSimon your suggestions and issues have been taken into account. So, a quick update: we have begun some internal discussions to try find the optimal solution to this issue for both Unity and users. This will probably take some time, but I’ll update this thread once we find an adequate solution.
For now, a temporary solution would be to rename the namespace and assembly of newtonsoft json. This would allow you to have your own copy and would avoid any collisions with the package.

2 Likes

manually putting

    "com.unity.nuget.newtonsoft-json": "2.0.0"

into the manifest.json seems to work, I’m using 2019.2, not sure about the implications tho

6 Likes

@Yemnefer The package supports 2018.4 and above as long as NET4 or Net Standard 2.0 is used. There should be no issues using in on 2018.4 and above. We cannot retroactively verify on older versions, so the package is only verified on 2020.1+.

3 Likes

good to know, thank you very much.

1 Like

It looks like the burst preview pacakge 1.3.0-preview.12 has newtonsoft JSON in its .Runtime forlder, which is causing issues when using something that depends on the com.unity.nuget.newtonsoft-json package.

How would I resolve this correctly?

The Burst .Runtime folder is outside of Unity, it’s a separate environment for the Burst command line tool. What problems are you having?

If you need it, I can set up another project again and give you a screen shot about the error, but basically, Unity reports a compiler error that there are two conflicting versions of NewtonSoft.Json.dll. One is in the com.unity.nuget.newtonsoft-json package, and one is in the burst preview pacakge 1.3.0-preview.12, in the .Runtime folder.

I didn’t need the latest burst preview, so I went through my packages and chose earlier versions that depend on the verified burst 1.2.3 and the problem went away. Also, in burst 1.2.3 the .Runtime folder does NOT contain the Newtonsoft dll. I didn’t check every version between 1.2.3 and the latest preview, but this appears to be a new addition. Regardless, as far as package management goes (especially with the strong named assemblies) burst should probably depend on the com.unity.nuget.newtonsoft-json package instead of providing its own.

If it isn’t clear, this is not about Burst actually running, as I’m sure there is no issue in the CLI tool, this is about Unity compilation errors when you have these conflicts in you’re packages.

Let me know if you need that example project, happy to help.

EDIT I managed to rebuild the dll’s to use the latest newtonsoft Json & it accepts the dll from test-framework.performance

Is there a way to fix this error? I had to remove the newtonsoft.Json that some addons are using in my project, because in 2020.x it gets stuck in a loop trying to open the editor (editor log has repeated spam about dll being the same name).

But now those addons don’t work with the dll that comes in from com.unity.collections which I need to use. ( com.unity.collections pulls in
“com.unity.test-framework.performance”: “2.3.1-preview”, )

references strong named Newtonsoft.Json in a different folder, versions has to match. Assembly references: 11.0.0.0 Found in project: 12.0.1.0.

I am having a similar issue and trying to get a handle on this. More information about how Unity may be fixing this is at

is it possible to use this “official” unity packaged version of json - with unity 2019 - and IOS/IL2CPP?

Thanks