Search code examples
jsonschemasyncthing

Generating JSON schema from syncthing JSON


Trying to generate JSON schema (http://jsonschema.net) from the syncthing (https://docs.syncthing.net/rest/system-connections-get.html) JSON below.

The problem is that the connection objects start with their ID (e.g. YZJBJFX-RDB...) which is interpreted as a type.

Is it the JSON from synching that isn't standard or is it the issue with the schema generator?

Do you have any suggestions how to get around this if schema generation is a requirement (I.e. no typing schemas manually).

{
    "total":{
        "paused":false,
        "clientVersion":"",
        "at":"2015-11-07T17:29:47.691637262+01:00",
        "connected":false,
        "inBytesTotal":1479,
        "type":"",
        "outBytesTotal":1318,
        "address":""
    },
    "connections":{
        "YZJBJFX-RDBL7WY-6ZGKJ2D-4MJB4E7-ZATSDUY-LD6Y3L3-MLFUYWE-AEMXJAC":{
            "connected":true,
            "inBytesTotal":556,
            "paused":false,
            "at":"2015-11-07T17:29:47.691548971+01:00",
            "clientVersion":"v0.12.1",
            "address":"127.0.0.1:22002",
            "type":"TCP (Client)",
            "outBytesTotal":550
        },
        "DOVII4U-SQEEESM-VZ2CVTC-CJM4YN5-QNV7DCU-5U3ASRL-YVFG6TH-W5DV5AA":{
            "outBytesTotal":0,
            "type":"",
            "address":"",
            "at":"0001-01-01T00:00:00Z",
            "clientVersion":"",
            "paused":false,
            "inBytesTotal":0,
            "connected":false
        },
        "UYGDMA4-TPHOFO5-2VQYDCC-7CWX7XW-INZINQT-LE4B42N-4JUZTSM-IWCSXA4":{
            "address":"",
            "type":"",
            "outBytesTotal":0,
            "connected":false,
            "inBytesTotal":0,
            "paused":false,
            "at":"0001-01-01T00:00:00Z",
            "clientVersion":""
        }
    }
}

Any input is appreciated.


Solution

  • Is it the JSON from synching that isn't standard or is it the issue with the schema generator?

    There is nothing non-standard about this JSON. Neither is there any issue with the schema generation.

    Unfortunately, defining a schema for what is effectively dynamic content is difficult. This will always be the case because the job of schemas is to describe static data structures.

    That said, it may be possible to do this using the patternProperties field in JSON schema. This post is effectively asking the same question as yours.