Reputation: 853
I'm looking for a way to unify two json schemas into one, by inserting one as a field of the other. That is to say, the schema A would have a property that is defined by the content of schema B.
To clarify,I don't want to reference schema A from schema B. I want to directly insert the content of B in a specific point of A so that I can have a single JSON document, but I figure that just "pasting" the content into the property programatically wouldn't be enough.
Upvotes: 0
Views: 928
Reputation: 645
JSON Schema is designed so that you can substitute a reference with its entire contents, and the behavior will be the same, with one possible exception if you use relative URI references.
If you have a schema like "A.json":
{
"type": "object",
"properties": {
"b": {"$ref": "B.json"}
}
}
And you have "B.json":
{ "type": "string" }
This can be collapsed into the following:
{
"type": "object",
"properties": {
"b": { "type": "string" }
}
}
There is one case in which the behavior would change, and that's if you use a relative URI reference, and the URI of the document you're substituting into causes that URI Reference to resolve to a full URI differently than it was before. Use a full (absolute) URI in the root of each schema, in these cases.
Upvotes: 1
Reputation: 59
I dint'get you question but I try to guess (it could be better if you added an example!). So i think that you have two schema like:
{ "schema": "A",
........
}
{"schema": "B",
.......
}
So, you have two chance to unify them: -manually -using a programm
Manually it is trivial because you have to do only copy and paste :
{ "schema": "B",
........
"schema_pasted": "A",
.......
}
or you can use some library to work automatically obtaing the same result (for exaple GSON https://github.com/google/gson in Java).
Upvotes: 0