Skip to content

fix(rest): parse text/json5 payloads with json5 crate instead of serd… - #2657

Open
xiao-yang25 wants to merge 2 commits into
eclipse-zenoh:mainfrom
xiao-yang25:fix/rest-json5-handing
Open

fix(rest): parse text/json5 payloads with json5 crate instead of serd…#2657
xiao-yang25 wants to merge 2 commits into
eclipse-zenoh:mainfrom
xiao-yang25:fix/rest-json5-handing

Conversation

@xiao-yang25

@xiao-yang25 xiao-yang25 commented Jun 27, 2026

Copy link
Copy Markdown

Title:
fix(rest): parse TEXT_JSON5 payloads with json5 crate
Body:

What

Use the json5 crate to parse TEXT_JSON5 encoded payloads in the REST plugin,
instead of treating them as strict JSON via serde_json.

Why

Fixes #2074

JSON5 payloads (unquoted keys, single-quoted strings, trailing commas, comments,
NaN/Infinity) are valid TEXT_JSON5 but fail serde_json parsing, causing an
unexpected base64 fallback that makes the data unreadable to consumers.

Behavior change

Scenario Before After
Valid JSON5 ({a: 1}) base64 string structured JSON ({"a":1})
Strict JSON structured JSON structured JSON (unchanged)
Unparseable text base64 string raw string
Non-UTF-8 bytes base64 string base64 string (unchanged)

Note: This is a breaking change for consumers that relied on the previous
base64 fallback behavior for JSON5 payloads.

Test plan

  • Unit tests: valid JSON5, strict JSON subset, unparseable fallback
  • cargo clippy -p zenoh-plugin-rest --all-targets -- --deny warnings
  • cargo test -p zenoh-plugin-rest

🏷️ Label-Based Checklist

Based on the labels applied to this PR, please complete these additional requirements:

Labels: bug

🐛 Bug Fix Requirements

Since this PR is labeled as a bug fix, please ensure:

  • Root cause documented - Explain what caused the bug in the PR description
  • Reproduction test added - Test that fails on main branch without the fix
  • Test passes with fix - The reproduction test passes with your changes
  • Regression prevention - Test will catch if this bug reoccurs in the future
  • Fix is minimal - Changes are focused only on fixing the bug
  • Related bugs checked - Verified no similar bugs exist in related code

Why this matters: Bugs without tests often reoccur.

Instructions:

  1. Check off items as you complete them (change - [ ] to - [x])
  2. The PR checklist CI will verify these are completed

This checklist updates automatically when labels change, but preserves your checked boxes.

…e_json

Previously, TEXT_JSON5 payloads were parsed with serde_json, which fails on
JSON5 syntax such as unquoted keys, comments, NaN, etc. This caused an
unexpected base64 fallback.

This now uses the json5 crate, with string fallback on parse failure, so
consumers always receive readable text.

Fixes eclipse-zenoh#2074

Signed-off-by: xiaoyang <xy1453417528@gmail.com>
@xiao-yang25

Copy link
Copy Markdown
Author

Could a maintainer please add the bug label to this PR? It fixes #2074, and the PR Checklist workflow currently requires at least one label.

@diogomatsubara diogomatsubara added the bug Something isn't working label Jul 23, 2026
@xiao-yang25

xiao-yang25 commented Jul 24, 2026

Copy link
Copy Markdown
Author

I've tested the changes and added the missing ZBytes import. Could a maintainer please approve and run the workflow when convenient? Thank you! @diogomatsubara

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REST API Inconsistency processing JSON5

2 participants