Can't get Newtonsoft.Json to work

Hi! I’m updating the savesystem to Json as shown in this blog post, but the code editor is not recongizing any of the Newtonsoft stuff. Before I started I checked in the Package Manager and there was no Newtonsoft package to speak of. So I installed it from com.unity.nuget.newtonsoft-json and with that the Package Manager installed Newtonsoft version 3.2.1. I thought I was ready, but I was very wrong.

Nothing changes when it comes to code. Intellisense does not recognize the classes nor the namespaces. If I try to edit the manifest, it warns me that “com.unity.nuget.newtonsoft-json”: “3.2.1” is already present (same if I set the version to 2.0.0 as suggested).

If I try to right click on any Json element in code and automatically add the package, it suggests Unity.Plastic.Newtonsoft.Json; Unity however is very unhappy with it and throws a truckload of errors when I switch to the editor; the repeating error is “Assets\Scripts\Core\Health.cs(4,13): error CS0234: The type or namespace name ‘Plastic’ does not exist in the namespace ‘Unity’ (are you missing an assembly reference?)”. If I remove Plastic, I get the same error but with ‘Newtonsoft’.

I can’t find any other namespace that contains JToken and the other stuff used in this blog.
I had tried just importing the Json save package and roll with it, but it has the same issues.

Help, please?

Which version of Unity are you using? It’s likely Newtonsoft is already there.

Take a screenshot of your Package Manager with the In Project packages.

1 Like


This is the screenshot.
The highlighted package is the one I installed myself. There was nothing with remotely similar names before I installed it.
It’s Unity 2022.3.2f1, so AFAIK it should be already included, but it’s not working nor with nor without that new package.

This is the correct package. When I wrote the tutorial, Unity didn’t ship with Newtonsoft, then it started with a subset only installed when needed for another dependency, and now in newer versions, it’s installed automatically.

The namespace you want to use in your code is

using Newtonsoft.Json.Linq;

It’s possible that VS Code isn’t picking up the packages with it’s intellisense. This is a common reccuring problem with a miriad of solutions that may or may not work.

First, make sure your VS Code package is up to date in Unity, and that VS Code is selected as your editor in Edit | Preferences | External Tools. Then click on Refresh Solution.

If that doesn’t work, another way (I call it the hard way!) is to close Unity and VSS and go into your project folder and delete the Library folder. This will force a rebuild and often fixes Intellisense.

Beyond that, there is another free code editor that actualy works, and that is Visual Studio Community. The screens won’t look the same as the instructors, but the intellisense will work! Personally, I use JetBrains Rider. It’s a paid program ($14.00 a month), but worth every penny (at least to me).

1 Like

The hard way worked, thanks!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms