Library(json)?

I’m using: SWI-Prolog version 9.2.9 which I installed from the stable Ubuntu repository. I’m on Linux Mint.

When I simply run swipl and type:

use_module(library(json)).

I’m informed that it doesn’t exist. The docs still say it’s there. Has this been replaced by something else?

In versions prior to 10.0, it is library(http/json). JSON support started in the http package, but has been moved to its own package. library(http/json) also works in > 10.0, though it prints a deprecation message there.

2 Likes

I was asking about library(json). The docs says it includes predicates like json_read and json_write. Is that in a separately installed pack? Should I consider it obsolete?

Apparently I was not clear :frowning: Let me try again. Up to version 10, JSON support (json_read/2, etc.) was provided by library(http/json). This is not library(http/http_json), which contains predicates that simplify JSON handling with HTTP using such as, reply_json/1.

Version 10 introduced a new package called json and the library(http/json) was moved to library(json). So, wherever the current docs talk about library(json), just use library(http/json). The predicates are the same.

So no, package json is not obsolete, but introduced in version 10. With package we refer to extensions bundled with the main source (as GIT submodules). Packages may or may not be activated while compiling the system from source. I.e., the sources allow selecting a set of packages so you can opt for a minimal system, the whole lot or something in between.

Thank You! I get it now and should have got that from your previous post. I think what tripped me up is that I just installed the stable version a few days ago and got confused about versions. I do agree that the predicates in what will be library(json) don’t necessarily involve http.

It does bring up another question. I think it’s related but if it is not considered so, go ahead and move it to a new topic. When will version 10 be in the stable Ubuntu ppa?

That is a little hard. The problem is that stable Ubuntu does not yet support SDL3. That is in the non-LTS releases, so it will be in LTS 26.04 I assume. We cannot provide a full PPA distribution for older Ubuntu (reasonably).

You can build from source, you can use the PPAs for the development series (current devel will be merged into 10.0.1 as all changes deal with portability, stricter C standard compliance and similar changes (no Prolog incompatibilities). Or you can use the flatpak (also only for the SWI-Prolog development series).

Thanks, I can wait. I just thought I’d use library(json) instead of library(http/json) if it’s a simple upgrade, but I definitely don’t require version 10. What’s in the stable ppa works fine.