nanoframework/Home

Bug in nanoFramework.Json: First character of string value is lost when it starts with \u00XX

Aperta

#1682 aperta il 24 ott 2025

 (9 commenti) (0 reazioni) (0 assegnatari) (89 fork)auto 404
Area: CL-nanoFramework.JsonArea: Targets (all)Priority: MediumStatus: Waiting triageType: Buggood first issuetrivialup-for-grabs

Metriche repository

Star
 (936 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

Library/API/IoT binding

nanoFramework.Json

Visual Studio version

VS2022

.NET nanoFramework extension version

2022.14.1.2

Target name(s)

ESP32-S3-WROOM

Firmware version

N/A

Device capabilities

No response

Description

When deserializing a JSON string using JsonConvert.DeserializeObject in .NET nanoFramework, the first character of a string value is completely dropped if it is represented as a Unicode escape sequence \u00XX (e.g., \u00225, \u00311, \u00412, etc.) and located at the beginning of the string value.


Example

Input JSON (valid, with escaping):

{\u0022Product\u0022:\u00225 test\u0022,\u0022Count\u0022:10}

Equivalent without escaping:

{"Product":"5 test","Count":10}

Target class:

public class Item
{
    public string Product { get; set; }
    public int Count { get; set; }
}

Deserialization code:

var obj = JsonConvert.DeserializeObject(json, typeof(Item)) as Item;
Debug.WriteLine(obj.Product);

Expected Result

5 test

Actual Result

 test

The character 5 (from \u00225) is completely lost.


Conditions

  • The string value starts with \u00XX.
  • \u00XX represents an ASCII character (digits 09, letters AF, etc.).
  • The escaping is valid and compliant with the JSON standard.

Root Cause

The nanoFramework.Json parser:

  • Processes \uXXXX sequences before completing string literal parsing.
  • Treats \u00XX at the start of a value as a separate token.
  • Discards the decoded character if it is the first one in the string.

This violates the JSON standard (RFC 8259), which requires \uXXXX inside strings to be properly decoded.


Impact

  • Data loss when receiving JSON from external APIs, CMS, or cloud services.
  • Inability to parse valid but escaped JSON.
  • Critical for IoT devices where JSON is the primary data exchange format.

Recommendation

  • Fix the parser in nanoFramework.Json to correctly handle \uXXXX inside string values.
  • Add unit tests for Unicode escapes at the start of strings.
  • Until fixed — always apply preprocessing when receiving escaped JSON.

Status: Critical Bug
Priority: High
Repository: nanoframework/nanoFramework.Json

How to reproduce

No response

Expected behaviour

No response

Screenshots

No response

Sample project or code

No response

Aditional information

No response

Guida contributor