JSONML checks childNode instead of the reserved childNodes attribute

Open Beginner friendly
#1,080 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java

Research direction

Start at JSONML.parse(), where the reserved-attribute check is shown, and trace the object-form path that later stores children under childNodes. Add regression coverage for rejecting childNodes while preserving childNode, then run the relevant JSONML tests or test suite and confirm array-form parsing remains unchanged.

Written by the indexing model from the issue text.

Description

The reserved-attribute check in JSONML.toJSONObject() checks childNode (singular), although the object representation uses childNodes (plural). As a result, a childNodes attribute is silently overwritten by the element's children, while an ordinary childNode attribute is rejected.

Reproduced on release 20260814 and current master (874673575807723d58bbec9ff1985668742940ce), with Java 17.0.20:

import org.json.JSONML;

System.out.println(JSONML.toJSONObject(
    "<p childNodes=\"metadata\">text</p>", true));
// {"childNodes":["text"],"tagName":"p"} -- attribute lost

System.out.println(JSONML.toJSONObject(
    "<p childNode=\"metadata\">text</p>", true));
// JSONException: Reserved attribute.

Expected: reject childNodes as reserved, as already happens for tagName, and preserve childNode as a regular attribute.

The check is in JSONML.parse(): "tagName".equals(attribute) || "childNode".equals(attribute). Later in the same method, newjo.put("childNodes", newja) overwrites the accepted attribute. Array-form parsing preserves both attribute names, so this affects the object form.

Dominant language
Java
Stars
4.7k
Forks
2.6k
Avg merge
6d 20h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stleary/JSON-java

All issues in stleary/JSON-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.