-
-
Couldn't load subscription status.
- Fork 85
Description
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. \u00XXrepresents an ASCII character (digits0–9, lettersA–F, etc.).- The escaping is valid and compliant with the JSON standard.
Root Cause
The nanoFramework.Json parser:
- Processes
\uXXXXsequences before completing string literal parsing. - Treats
\u00XXat 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.Jsonto correctly handle\uXXXXinside 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