Orthanc Json contains comment

Hi there,

I'm trying to build a GUI to parse and generate the Orthanc.Json

I have a problem : the original Orthanc.Json has comments with "//" while it seems that it is not allowed into the Json format (https://stackoverflow.com/questions/244777/can-comments-be-used-in-json)

So my Java library do not parse correctly the orthanc.json unless I remove all comments.

Is there a way orthanc.json will evolve to a standard json or should I avoid to make a parser ? (and my software will only be a json generator)

Best regards,



I think it is very reasonable for your parser to forbid comments in the
Orthanc configuration files. Although I wish Orthanc would use standard
JSON (or something else) I think the inline comments in the sample
configurations are too helpful for beginners.

Note that these sample configurations with comments are just that;
sample files. In many contexts I actually strive to write standard JSON
in Orthanc configuration files (mostly because I'm annoyed by syntax
highlighters and linters otherwise).

If this is a problem for some reason and you really need to accept the
sample files in your parser, I'd advise you to perform a pre-processing
step that strips the comments before feeding the data to the JSON
parser. This may or may not involve some edge-cases, but it seems
reasonable and is what is recommended by JSON designers[1]. There are
many projects that allow you to do that[2][3][4].

Finally if all of this is unsatisfactory you may want to contribute
support for an alternative format like hjson[5] or yaml[6], which might
indeed be more appropriate for Orthanc configuration files.

[1] https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaGSr
[2] http://www.crockford.com/javascript/jsmin.html
[3] https://github.com/getify/JSON.minify
[4] https://www.npmjs.com/package/strip-json-comments
[5] http://hjson.org/
[6] http://www.yaml.org/

Best regards,

Thanks Thibault for this help !
I tried jsmin for which I found a Java code here (https://github.com/galan/packtag/tree/0b0b1e18944ff6ecdf81f2dd286ae9221e5c8fbd) and it works like a charm !

My road is still long to get the GUI to parse / generate the orthanc.json but I'm making progress step by step.

I will keep you updated,

Best regards,


Hi there,

I'm making progress on my GUI to edit the Orthanc Json, it is almost ready.

I have 2 questions :

- In the Orthanc.Json there are 2 commented parameters : PKCS and Locale. Are those parameter low important enough to be skipped from my GUI ?

- My software is made to parse JSON for the 1.3.0 while the JSON get new parameters in the newest version. If I generate a JSON following the 1.3.0, is this file will be compatible with the older version of Orthanc ? (in short is Orthanc 1.2.0 will have problem to read the actual JSON of 1.3.0 ?) Otherwise it will be hard to generate special JSON for each JSON

The beta version of my software is in Java and can be downloaded from here :https://github.com/salimkanoun/Ortanc_Json_Editor/releases/download/0.1/Orthanc_Editor.jar

This is a pre-release, some bugs might be present and this version only parse Orthanc 1.3.0 JSON.
However I would be pleased to get feedback from the community as bug report or feature request.
Before the 1.0 version I will try to include a "Restart" button to restart Orthanc Server after a JSON generation

The sources are available in the GitHub.

Best regards,


Hi Salim,

Yes, you can skip PKCS, it’s a very advanced feature very few people will use.
Same for ‘Locale’.

Concerning the backward compatibility: Orthanc 1.2.0 will just ignore most of the new parameters introduced in version 1.3.0. However, you might have some issues with the Modality types that might not be recognized by Orthanc 1.2.0 and it might stop on the parameters it does not know.

I just gave it a quick try and I can confirm it works fine on my Win10 PC. Thanks for the work !


Thanks Alain for the feedback. I'm working on Linux, the only OS don't have access is MacOS, however i'm only using few librairies and basic JAVA services, it should work in every computer capable to run the Java virtual machine no matter of the OS.

So I will skip PKCS ans Locale in this software.

For the compatibility I forgot about the manifacturer tags, so I will not support orthanc JSON's before the 1.3.0 version.
In the next version If your JSON evolve I will have to update this software, so I will make a new version for each release of Orthanc. I will let the previous versions on GitHub so the support will start at Orthanc 1.3.0.

I will try to add the Orthanc API restart, the management of certificates in Orthanc Peers and some code cleaning and I think we will be OK for a release.

Best regards,


Here a new version with Orthanc Server Restart and better parsing (JSON reading from older version of Orthanc should work)


Just have to manage Orthanc Peer Certificate and should be OK (unless someone depict bugs)


Finally I will skip the the Orthanc Peer Certificate because this settings change type depending on the presence of certificate or not (JSON Array or Object).
Not that it is impossible to support it but it will introduce a new level of complexity in the code and the GUI. Might be done if someone really need it.

So I have a release candidate : https://github.com/salimkanoun/Ortanc_Json_Editor/releases/download/0.9/OrthancEditor.jar

I will wait few day to see if I get some bug reports and then announce it.


I am looking for an update on this too. This is not a standard json file because of the // lines and // blocks.
I am building an interface that needs to read AE title and port of the server and I am stuck. Cannot parse the files because of these comments.
I can do PHP or some jquery libraries, but no luck till now. Eventually I will need to write back to json, so is there a solution to this?
Some are saying using yaml, json.net, json5, hjson, json.minify, etc. There are multiple options but first I should check with Orthanc if there is a parser for this.
Maybe there is a command line that I can use and gather specific fields, delete/add DicomModalities, etc
Please let me know which way is easier and makes sense for me to implement.
Thank you,

Hi Emil,

You can get most of the info through the REST api. You can also add/modify & delete remote modalities through the API if you set the “DicomModalitiesInDatabase” option.



Lua scripts and plugins have access to the full JSON configuration of Orthanc, with the comments removed, and with all the configuration files merged as a single file.

Here is a sample Lua script to write the plain configuration to the filesystem at the Orthanc startup:

function Initialize()
file = io.open(“/tmp/config.json”, “w”)

Plugins also have access to the full configuration using the SDK function “OrthancPluginGetConfiguration()”. Plugins can be used for more flexibility, as they are able to add new routes in the REST API of Orthanc:

Here is a sample Python plugin that published a pretty-print version of the configuration on the REST route “/config”:

import orthanc
import json

def OnRest(output, uri, **request):
pretty = json.dumps(json.loads(orthanc.GetConfiguration()), indent = 4)

output.AnswerBuffer(pretty, ‘application/json’)

orthanc.RegisterRestCallback(‘/config’, OnRest)

You can find more information about Python plugins at the following location:

Obviously, be careful to upgrade this script by removing sensitive information (such as “RegisteredUsers”) if the new REST route is accessible outside of the localhost.


I set up DicomModalitiesInDatabase to true, but if I restart the Orthanc service, the modalities are gone. Database should store them permanently…
any idea why?

Hi Emil,

What database are you using? If you are running in a Docker container, are you saving the database outside the container? https://book.orthanc-server.com/users/docker.html?highlight=docker#id7


sorry, my bad. The database was set on false. I did an update of Orthanc and forgot to turn it back to true.

another thing to add is that when you add a node, orthanc does not check for ip validity, like I could add 192 or hhh. Maybe because it allows domains. I don’t know.
Ports, seems to work, it will throw an error if outside range. Same for AET inputs, it will check for spaces as far I can see.

So I will need to implement some validators for the IP field.

Thanks Sébastien,
I end up using jquery and works quite well.
Listing nodes:
$.fn.nodescall = function() {
url: “http://localhost:8042/modalities?expand”,
cache: false,
success: function (data) {
$(‘#remotenode’).html(“Remote Nodes allowed to transfer data in:
$.each(data, function(k, v) {
$.each(v, function(k1, v1) {
if(k1==“AET”) $(‘#remotenode’).append(k1+“: “+v1+”
if(k1==“Host”) $(‘#remotenode’).append(k1+“: “+v1+”
if(k1==“Port”) $(‘#remotenode’).append(k1+“: “+v1+”
//refresh node list

$(‘#addnode’).click(function() {
var aet_val=$(“#aet_field”).val();
var host_val=$(“#host_field”).val();
var port_val=$(“#port_field”).val();
if(aet_val!=“” && host_val!=“” && port_val!=“”) {
url: “http://localhost:8042/modalities/”+aet_val,
type: ‘PUT’,
cache: false,
data: JSON.stringify({“AET” : aet_val, “Host”: host_val, “Port”: port_val}),
success: function (data) {
$(‘#nodemessage’).empty().show().html(“Node added!”).delay(5000).fadeOut(‘slow’);
//refresh the list of displayed nodes
error: function(){
$(‘#nodemessage’).empty().show().html(“Something went wrong!”).delay(5000).fadeOut(‘slow’);
} else $(‘#nodemessage’).empty().show().html(“Please fill up all 3 fields!”).delay(5000).fadeOut(‘slow’);

And deleting:
var aet_val = this.id;
url: “http://localhost:8042/modalities/”+aet_val,
type: ‘DELETE’,
success: function (result) {
$(‘#nodemessage’).empty().show().html(“Node deleted!”).delay(5000).fadeOut(‘slow’);
//refresh the list of displayed nodes
error: function(){
$(‘#nodemessage’).empty().show().html(“Something went wrong!”).delay(5000).fadeOut(‘slow’);