Index: binary-improvements/MapRendering/API/GetPlayerInventory.cs
===================================================================
--- binary-improvements/MapRendering/API/GetPlayerInventory.cs	(revision 454)
+++ binary-improvements/MapRendering/API/GetPlayerInventory.cs	(revision 455)
@@ -1,10 +1,12 @@
 using System.Collections.Generic;
 using System.Net;
-using AllocsFixes.JSON;
 using AllocsFixes.PersistentData;
+using JetBrains.Annotations;
+using Utf8Json;
 using Webserver;
 using Webserver.WebAPI;
 
 namespace AllocsFixes.WebAPIs {
+	[UsedImplicitly]
 	public class GetPlayerInventory : AbsWebAPI {
 		public override void HandleRequest (RequestContext _context) {
@@ -28,7 +30,7 @@
 			GetInventoryArguments (_context, out bool showIconColor, out bool showIconName);
 
-			JSONObject result = DoPlayer (p, showIconColor, showIconName);
-
-			LegacyApiHelper.WriteJSON (_context.Response, result);
+			JsonWriter writer = new JsonWriter ();
+			DoPlayer (ref writer, p, showIconColor, showIconName);
+			WebUtils.WriteJsonData (_context.Response, ref writer);
 		}
 
@@ -43,47 +45,82 @@
 		}
 
-		internal static JSONObject DoPlayer (Player _player, bool _showIconColor, bool _showIconName) {
+		private static readonly byte[] jsonKeyUserId = JsonWriter.GetEncodedPropertyNameWithBeginObject ("userid");
+		private static readonly byte[] jsonKeyCrossPlatformId = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("crossplatformid");
+		private static readonly byte[] jsonKeyEntityId = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("entityid");
+		private static readonly byte[] jsonKeyPlayerName = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("playername");
+		private static readonly byte[] jsonKeyBag = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("bag");
+		private static readonly byte[] jsonKeyBelt = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("belt");
+		private static readonly byte[] jsonKeyEquipment = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("equipment");
+
+		internal static void DoPlayer (ref JsonWriter _writer, Player _player, bool _showIconColor, bool _showIconName) {
 			PersistentData.Inventory inv = _player.Inventory;
-
-			JSONObject result = new JSONObject ();
-
-			JSONArray bag = new JSONArray ();
-			JSONArray belt = new JSONArray ();
-			JSONObject equipment = new JSONObject ();
-			result.Add ("userid", new JSONString (_player.PlatformId.CombinedString));
-			result.Add ("crossplatformid", new JSONString (_player.CrossPlatformId?.CombinedString ?? ""));
-			result.Add ("entityid", new JSONNumber (_player.EntityID));
-			result.Add ("playername", new JSONString (_player.Name));
-			result.Add ("bag", bag);
-			result.Add ("belt", belt);
-			result.Add ("equipment", equipment);
-
-			DoInventory (belt, inv.belt, _showIconColor, _showIconName);
-			DoInventory (bag, inv.bag, _showIconColor, _showIconName);
-
-			AddEquipment (equipment, "head", inv.equipment, EquipmentSlots.Headgear, _showIconColor, _showIconName);
-			AddEquipment (equipment, "eyes", inv.equipment, EquipmentSlots.Eyewear, _showIconColor, _showIconName);
-			AddEquipment (equipment, "face", inv.equipment, EquipmentSlots.Face, _showIconColor, _showIconName);
-
-			AddEquipment (equipment, "armor", inv.equipment, EquipmentSlots.ChestArmor, _showIconColor, _showIconName);
-			AddEquipment (equipment, "jacket", inv.equipment, EquipmentSlots.Jacket, _showIconColor, _showIconName);
-			AddEquipment (equipment, "shirt", inv.equipment, EquipmentSlots.Shirt, _showIconColor, _showIconName);
-
-			AddEquipment (equipment, "legarmor", inv.equipment, EquipmentSlots.LegArmor, _showIconColor, _showIconName);
-			AddEquipment (equipment, "pants", inv.equipment, EquipmentSlots.Legs, _showIconColor, _showIconName);
-			AddEquipment (equipment, "boots", inv.equipment, EquipmentSlots.Feet, _showIconColor, _showIconName);
-
-			AddEquipment (equipment, "gloves", inv.equipment, EquipmentSlots.Hands, _showIconColor, _showIconName);
-
-			return result;
+			
+			_writer.WriteRaw (jsonKeyUserId);
+			_writer.WriteString (_player.PlatformId.CombinedString);
+			
+			_writer.WriteRaw (jsonKeyCrossPlatformId);
+			_writer.WriteString (_player.CrossPlatformId?.CombinedString ?? "");
+			
+			_writer.WriteRaw (jsonKeyEntityId);
+			_writer.WriteInt32 (_player.EntityID);
+			
+			_writer.WriteRaw (jsonKeyPlayerName);
+			_writer.WriteString (_player.Name);
+			
+			_writer.WriteRaw (jsonKeyBag);
+			DoInventory (ref _writer, inv.bag, _showIconColor, _showIconName);
+			
+			_writer.WriteRaw (jsonKeyBelt);
+			DoInventory (ref _writer, inv.belt, _showIconColor, _showIconName);
+			
+			_writer.WriteRaw (jsonKeyEquipment);
+			DoEquipment (ref _writer, inv.equipment, _showIconColor, _showIconName);
+			
+			_writer.WriteEndObject ();
 		}
 
-		private static void DoInventory (JSONArray _jsonRes, List<InvItem> _inv, bool _showIconColor, bool _showIconName) {
+		private static void DoInventory (ref JsonWriter _writer, IReadOnlyList<InvItem> _inv, bool _showIconColor, bool _showIconName) {
+			_writer.WriteBeginArray ();
 			for (int i = 0; i < _inv.Count; i++) {
-				_jsonRes.Add (GetJsonForItem (_inv [i], _showIconColor, _showIconName));
+				if (i > 0) {
+					_writer.WriteValueSeparator ();
+				}
+				GetJsonForItem (ref _writer, _inv [i], _showIconColor, _showIconName);
 			}
+			_writer.WriteEndArray ();
 		}
 
-		private static void AddEquipment (JSONObject _eq, string _slotname, InvItem[] _items, EquipmentSlots _slot, bool _showIconColor, bool _showIconName) {
+		private static void DoEquipment (ref JsonWriter _writer, IReadOnlyList<InvItem> _equ, bool _showIconColor, bool _showIconName) {
+			_writer.WriteBeginObject ();
+			
+			AddEquipment (ref _writer, "head", _equ, EquipmentSlots.Headgear, _showIconColor, _showIconName);
+			_writer.WriteValueSeparator ();
+			AddEquipment (ref _writer, "eyes", _equ, EquipmentSlots.Eyewear, _showIconColor, _showIconName);
+			_writer.WriteValueSeparator ();
+			AddEquipment (ref _writer, "face", _equ, EquipmentSlots.Face, _showIconColor, _showIconName);
+			_writer.WriteValueSeparator ();
+
+			AddEquipment (ref _writer, "armor", _equ, EquipmentSlots.ChestArmor, _showIconColor, _showIconName);
+			_writer.WriteValueSeparator ();
+			AddEquipment (ref _writer, "jacket", _equ, EquipmentSlots.Jacket, _showIconColor, _showIconName);
+			_writer.WriteValueSeparator ();
+			AddEquipment (ref _writer, "shirt", _equ, EquipmentSlots.Shirt, _showIconColor, _showIconName);
+			_writer.WriteValueSeparator ();
+
+			AddEquipment (ref _writer, "legarmor", _equ, EquipmentSlots.LegArmor, _showIconColor, _showIconName);
+			_writer.WriteValueSeparator ();
+			AddEquipment (ref _writer, "pants", _equ, EquipmentSlots.Legs, _showIconColor, _showIconName);
+			_writer.WriteValueSeparator ();
+			AddEquipment (ref _writer, "boots", _equ, EquipmentSlots.Feet, _showIconColor, _showIconName);
+			_writer.WriteValueSeparator ();
+
+			AddEquipment (ref _writer, "gloves", _equ, EquipmentSlots.Hands, _showIconColor, _showIconName);
+			
+			_writer.WriteEndObject ();
+		}
+
+		private static void AddEquipment (ref JsonWriter _writer, string _slotname, IReadOnlyList<InvItem> _items, EquipmentSlots _slot, bool _showIconColor, bool _showIconName) {
+			_writer.WritePropertyName (_slotname);
+
 			int[] slotindices = XUiM_PlayerEquipment.GetSlotIndicesByEquipmentSlot (_slot);
 
@@ -91,36 +128,52 @@
 				if (_items? [slotindices [i]] != null) {
 					InvItem item = _items [slotindices [i]];
-					_eq.Add (_slotname, GetJsonForItem (item, _showIconColor, _showIconName));
+					
+					GetJsonForItem (ref _writer, item, _showIconColor, _showIconName);
 					return;
 				}
 			}
 
-			_eq.Add (_slotname, new JSONNull ());
+			// Slot not found / empty
+			_writer.WriteNull ();
 		}
 
-		private static JSONNode GetJsonForItem (InvItem _item, bool _showIconColor, bool _showIconName) {
+		private static readonly byte[] jsonKeyCount = JsonWriter.GetEncodedPropertyNameWithBeginObject ("count");
+		private static readonly byte[] jsonKeyName = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("name");
+		private static readonly byte[] jsonKeyIcon = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("icon");
+		private static readonly byte[] jsonKeyIconColor = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("iconcolor");
+		private static readonly byte[] jsonKeyQuality = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("quality");
+		private static readonly byte[] jsonKeyQualityColor = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("qualitycolor");
+
+		private static void GetJsonForItem (ref JsonWriter _writer, InvItem _item, bool _showIconColor, bool _showIconName) {
 			if (_item == null) {
-				return new JSONNull ();
+				_writer.WriteNull ();
+				return;
 			}
-
-			JSONObject jsonItem = new JSONObject ();
-			jsonItem.Add ("count", new JSONNumber (_item.count));
-			jsonItem.Add ("name", new JSONString (_item.itemName));
+			
+			_writer.WriteRaw (jsonKeyCount);
+			_writer.WriteInt32 (_item.count);
+			
+			_writer.WriteRaw (jsonKeyName);
+			_writer.WriteString (_item.itemName);
 			
 			if (_showIconName) {
-				jsonItem.Add ("icon", new JSONString (_item.icon));
+				_writer.WriteRaw (jsonKeyIcon);
+				_writer.WriteString (_item.icon);
 			}
 
 			if (_showIconColor) {
-				jsonItem.Add ("iconcolor", new JSONString (_item.iconcolor));
+				_writer.WriteRaw (jsonKeyIconColor);
+				_writer.WriteString (_item.iconcolor);
 			}
 
-			jsonItem.Add ("quality", new JSONNumber (_item.quality));
+			_writer.WriteRaw (jsonKeyQuality);
+			_writer.WriteInt32 (_item.quality);
+
 			if (_item.quality >= 0) {
-				jsonItem.Add ("qualitycolor", new JSONString (QualityInfo.GetQualityColorHex (_item.quality)));
+				_writer.WriteRaw (jsonKeyQualityColor);
+				_writer.WriteString (QualityInfo.GetQualityColorHex (_item.quality));
 			}
-
-			return jsonItem;
-
+			
+			_writer.WriteEndObject ();
 		}
 	}
