Suggestions for a C JSON library

Post Reply

Topic author
mjimji
Contributor
Posts: 13
Joined: Thu Oct 22, 2020 11:24 am
Reputation: 0
Status: Offline

Suggestions for a C JSON library

Post by mjimji » Thu Jan 14, 2021 6:22 am

Hi all,

I'm looking for a JSON library written in C, does anyone have any suggestions?

I need to:
  • Parse JSON from a file or memory and process the in-memory JSON document
  • Create an in-memory JSON document
  • Output an in-memory JSON document to a file or to memory
  • Read and process a JSON file in streaming mode
  • Write a JSON file in streaming mode
The best match I have found is WJElement. I can find no evidence that anyone has ever used it on OpenVMS but I don't think that should be a major problem.

Thanks,

Mark

User avatar

arne_v
Master
Posts: 299
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: Suggestions for a C JSON library

Post by arne_v » Mon Jan 18, 2021 2:11 pm

The only C JSON library I have used on VMS is cJSON and it does not support streaming read or streaming write.

But do you really need those?

Streaming write is rather trivial. A dozen C macros wrapping fprintf would provide what libraries provide.

Streaming read without any restrictions van be tricky. But if you know that each line contains valid JSON then something can be written on top of a standard JSON parser.
Arne
arne@vajhoej.dk
VMS user since 1986


brett.cameron
VSI Expert
Active Contributor
Posts: 25
Joined: Mon Jun 24, 2019 9:51 am
Reputation: 0
Status: Offline

Re: Suggestions for a C JSON library

Post by brett.cameron » Mon Jan 18, 2021 6:16 pm

We tend to use either https://github.com/DaveGamble/cJSON or https://github.com/json-c/json-c. Both work fine, for most tasks although cJSON is arguably somewhat simpler to use, but is possibly not so functionally rich. JSON-C does explicitly include functionality to read in a JSON document from disk.

WJElement also builds and works okay on OpenVMS (with one or two minor code modifications), but it needs some extra bits and pieces, namely libregex (assuming you wish to use REGEX functionality).


Topic author
mjimji
Contributor
Posts: 13
Joined: Thu Oct 22, 2020 11:24 am
Reputation: 0
Status: Offline

Re: Suggestions for a C JSON library

Post by mjimji » Wed Jan 20, 2021 4:58 am

Thanks Arne & Brett.

It's good to know that WJElement builds and works okay, so that's definitely my most likely choice. If not, then I would probably go with cJSON for non-streaming and perhaps https://github.com/mnunberg/jsonsl for streaming reading. As you say, Arne, streaming writing is rather trivial.

Mark


jfp
Contributor
Posts: 16
Joined: Wed Jun 17, 2020 6:34 am
Reputation: 0
Status: Offline

Re: Suggestions for a C JSON library

Post by jfp » Thu Jan 21, 2021 11:46 am

There is a port of cJSON on foss.vmsgenerations.org and a build version is provided with python, in libraries the LD image

https://foss.vmsgenerations.org/openvms/libraries/cjson

If you want to rebuild from sources and have Python installed on your VMS system just do a "hg clone" else download a zip or any other format provided.
Be sure to update to the vms branch or to download the vms branch,

JF

Post Reply