Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

jsonschema - Is the a way to validate object references within JSON with JSON schema?

Let's take a simple example when we define objects and use them separately within JSON. For instance, we define several addresses and use them to define several routes:

{
    "points": [
        {
            "Name": "p1",
            "Street": "street1",
            "House": 11,
            "Ap": 111
        },
        {
            "Name": "p2",
            "Street": "street2",
            "House": 22,
            "Ap": 222
        },
        {
            "Name": "p3",
            "Street": "street3",
            "House": 33,
            "Ap": 333
        },
        {
            "Name": "p4",
            "Street": "street4",
            "House": 44,
            "Ap": 444
        },
        {
            "Name": "p5",
            "Street": "street5",
            "House": 55,
            "Ap": 555
        }

    ],
    "routes": [
        [
            "p1",
            "p2",
            "p3",
            "p4"
        ],
        [
            "p3",
            "p2",
            "p1"            
        ],
        [
            "p4",
            "p2",
            "p3",
            "p1"
        ]
    ]
}

What would be a right way, if any, to validate with JSON schema, that all routes refer to defined addresses? Sorry if my question is too newbie. Thanks,

question from:https://stackoverflow.com/questions/66066787/json-schema-reference-enum-like-a-reference-to-array

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You cannot use JSON Schema to validate relational data represented in JSON has referencial integrity.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...