json_encode() re-emits a decoded empty JSON object as [], so {} and {"":1} are not round-trip stable
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start by reading .json_write() and the .json_array_of() path mentioned in the issue. Check how decoded lists with an empty names attribute and with an empty-string key are classified, then run the relevant JSON codec tests. Done means those cases encode as JSON objects and the listed round trips remain stable.
Written by the indexing model from the issue text.
Description
json_encode() re-emits a decoded JSON object as an array whenever every key is empty: {} becomes [], {"a":{}} becomes {"a":[]}, and {"":1} becomes [1], so the codec is not round-trip stable for objects.
library(rssn)
str(json_decode("{}")) # Named list() -- decoded correctly as an object
json_encode(json_decode("{}")) # "[]" -- should be "{}"
json_encode(json_decode('{"a":{}}')) # '{"a":[]}' -- should be '{"a":{}}'
json_encode(json_decode('{"":1}')) # "[1]" -- should be '{"":1}'
Actual round-trip stability:
{} -> [] -> [] stable=FALSE
{"a":{}} -> {"a":[]} -> {"a":[]} stable=FALSE
{"":1} -> [1] -> [1] stable=FALSE
[] -> [] -> [] stable=TRUE
json_decode() does its job: str(json_decode("{}")) is Named list() (a names attribute of character(0), distinct from the NULL names of []), and str(json_decode('{"":1}')) carries the name "". The defect is in .json_write(), which decides object-vs-array with if (!is.null(names) && any(nzchar(names))): an empty names vector, or one whose only entries are "", fails any(nzchar(...)) and falls through to .json_array_of(). The presence of a names attribute (even empty) is what marks a JSON object, so the test should not require a non-empty name.
This makes json_encode(json_decode(x)) lossy for any API response containing an empty object or an empty-string key, and it is independent of the escaping defects in #302/#303/#307 (no strings with escapes are involved here).
rssn 0.3.0, R 4.6.2 binding, Windows x86_64.
- Dominant language
- Rust
- Stars
- 36
- Forks
- 3
- Avg merge
- 14h 51m
- Merged PRs (30d)
- 29
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Apich-Organization/rssn
-
num_ode_rk4_adaptive rejects atol = 0 while accepting rtol = 0 and while num_ode_dopri5 accepts bothOpenarea/ode-pde good first issue help wanted kind/contract severity/4-minor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Apich-Organization/rssn#383 ·
Maintainers usually reply within 1 day
-
area/numerical good first issue help wanted kind/doc-mismatch severity/5-trivial
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Apich-Organization/rssn#373 ·
Maintainers usually reply within 1 day
-
area/numerical good first issue help wanted kind/doc-mismatch severity/4-minor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Apich-Organization/rssn#371 ·
Maintainers usually reply within 1 day
-
area/statistics good first issue help wanted kind/wrong-result severity/4-minor
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Apich-Organization/rssn#362 ·
Maintainers usually reply within 1 day
-
area/statistics good first issue help wanted kind/wrong-result severity/3-major
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Apich-Organization/rssn#358 ·
Maintainers usually reply within 1 day
All issues in Apich-Organization/rssn
Similar issues
-
claim
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Nixitov/Riptide-Native#946 ·
Maintainers usually reply within 1 day
-
area: ai-assistants documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
BetaBots-LLC/latticegate#17 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
storytold/craft-libs#5594 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
听歌识曲历史跳转后对应音源界面无法返回Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
LingyunStudio/RustMusic#16 ·