8000
Skip to content

Replace custom JSON implementation with cJSON library#2034

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/replace-custom-json-library
Draft

Replace custom JSON implementation with cJSON library#2034
Copilot wants to merge 4 commits intomasterfrom
copilot/replace-custom-json-library

Conversation

Copy link
Copy Markdown
Contributor
Copilot AI commented Jan 4, 2026

The custom JSON parser/serializer is a maintenance burden and potential source of bugs. This replaces it with the well-tested cJSON library.

Changes

  • configure: Add libcjson as a required pkg-config dependency
  • src/misc/json.c: Replace ~400 line recursive descent parser with cJSON-based implementation (~90 lines)
  • src/htsmsg_json.c: Replace custom serializer with cJSON's cJSON_Print/cJSON_PrintUnformatted

The existing json_deserializer_t callback abstraction is preserved, so no changes needed in calling code.

// Parsing now uses cJSON internally
cJSON *root = cJSON_Parse(src);
// Then converts to htsmsg via existing callbacks
result = json_convert_item(root, NULL, NULL, jd, opaque);
cJSON_Delete(root);

Notes

  • htsbuf_append_and_escape_jsonstr() retained in htsbuf.c for webui.c usage
  • cJSON uses standard malloc/free by default, maintaining ABI compatibility

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 239.255.255.250
    • Triggering command: REDACTED, pid is -1 (packet block)
  • my.pcloud.com
    • Triggering command: /usr/bin/python /usr/bin/python /home/REDACTED/work/tvheadend/tvheadend/support/pcloud.py publink_download kZ54ee7ZUvsSYmb9VGSpnmoVzcAUhpBXLq8k misc/staticlib/Ubuntu 24.04/x86_64/ffmpeg-bb54fc09477ff26635f40d84dd893daf43dd9090.tgz /home/REDACTED/work/tvheadend/tvheadend/build.linux/.ffmpeg-bb54fc09477ff26635f40d84dd893daf43dd9090.tgz.tmp -I adend -I linux-gnu/dbus-1.0/include -I adend/build.linux/src/descrambler/algo/libaesdec--64 -I in.so /lto-wrapper ndor/bin/git -I linux-gnu/dbus-1abcdefghijklmnopqrstuvwxyz -I k/tvheadend/tvheadend/build.linu-o (dns block)
    • Triggering command: /usr/bin/python3 python3 /home/REDACTED/work/tvheadend/tvheadend/support/pcloud.py publink_download kZ54ee7ZUvsSYmb9VGSpnmoVzcAUhpBXLq8k misc/staticlib/Ubuntu 24.04/x86_64/ffmpeg-bb54fc09477ff26635f40d84dd893daf43dd9090.tgz /home/REDACTED/work/tvheadend/tvheadend/build.linux/.ffmpeg-bb54fc09477ff26635f40d84dd893daf43dd9090.tgz.tmp -I adend -I linux-gnu/dbus-1.0/include -I adend/build.linux/src/descramble/tmp/7355.bin -I on -I rgo/bin/as -I linux-gnu/dbus-1.0/include -I k/tvheadend/tvheadend/build.linux (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Replace the custom json creation/parsing with an appropriate library in order to reduce the risk of bugs and reduce the maintenance burden


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 4, 2026 01:19
- Add cJSON as a required dependency in configure script
- Replace custom JSON parser in src/misc/json.c with cJSON-based implementation
- Replace custom JSON serializer in src/htsmsg_json.c with cJSON-based implementation
- The new implementation uses the well-tested cJSON library for both parsing and
  serialization, reducing the risk of bugs and maintenance burden

Co-authored-by: Flole998 <9951871+Flole998@users.noreply.github.com>
Co-authored-by: Flole998 <9951871+Flole998@users.noreply.github.com>
Co-authored-by: Flole998 <9951871+Flole998@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace custom JSON creation and parsing with library Replace custom JSON implementation with cJSON library Jan 4, 2026
Copilot AI requested a review from Flole998 January 4, 2026 01:47
@sonarqubecloud
Copy link
Copy Markdown
sonarqubecloud bot commented Jan 4, 2026

@dave-p
Copy link
Copy Markdown
Contributor
dave-p commented Jan 4, 2026

Tested using the Tvheadend UI and the HTTP API. No issues found.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0