Hei Guys,
I wonder if it is possible to edit jsons according to json schemas like settings.json in a ui form in vs code?
Can anyone tell if this is possible in vs code?
Yep! Although support for $schema in instance data isn't something that JSON Schema defines, it has become something of a convention.
VSCode supports declaring $schema in your data, and even supports relative paths.
In this example, my JSON data file Untitled-1.json is defined in the same folder as schema.json.
Related
I am working with JSON schema for a file, which keeps a set of variables we are using to define our configuration, which will be executed through Ansible. Importantly, we are using JSON schema to validate YAML files.
So far everything goes well. However, I have this challenge.
I have a file called common.yml and other called domain.yml. Inside domain.yml we have a property called domain_root, which depends on a property called common_dir, which is inside common.yml and I have not found any documentation on how to define a dependency when the property is in place, but in another file.
By the way, dependencies in the same file are working without issues.
"dependencies": {
"domain_home": ["domain_parent_dir", "domain_name"],
"domain_libraries":["domain_home"],
"logs_directory":["oracle_user", "domain_name"],
}
Please, if you have any clues, kindly help me.
Best regards,
RCC
You cannot. JSON Schema actually doesn't work with files at all. JSON Schema implementations may load a file to get to the JSON, but JSON Schema knows nothing about files in a filesystem.
In stead, consider combining your multiple files into a single file for validation purposes.
This doesn't help if you want validation in-editor, but could help if you only need validation as part of a continuious intergration (CI) process.
I need some guidance on how to proceed with a problem.
Our integration team receives xml files which are converted to json and sent to pub/sub. We then ingest the json files (or are supposed to) into bigquery.
The problem is that the xml files do not include all possible objects or values all the time. So, I cant create a correct schema in bq to receive the json files. I got the xsd file with an extension file which gives me all possible objects but I don't know how to convert this to a correct bq schema.
Do you have any suggestions on how to create a bq schema from xsd files? I was thinking that if I create an xml file with dummy data (including all objects and more than one object when creating repeated objects) with help of the xsd maybe that xml file may be converted to json and then use the auto-schema detection of bq.
Any suggestions?
Thanks,
Cris
If you have the XSD schema files, you can convert these to a valid JSON schema. There are a few tools that can help you to accomplish this.
Keep in mind that the tools are for general purposes and not for the particular case of BigQuery, so you'll have to tune the result to get a valid JSON schema. For this check the components of a BigQuery schema, and for quick reference the sample provided in the documentation.
I'm creating an npm package which contains a schema file, set.schema.json. I'm wondering how I can set this as the $schema of a JSON file in another project with this package installed as a dependency. I'm mainly using the schema for IDE suggestions, rather than validation.
JSON Schema does not specify a way to do this.
Any way you want to do this needs to be supported by the IDE in question.
Is there any naming convention for a json schema file extension? XML has .xsd (XML Schema Definition), what should json schema files have, .jsd (JSON Schema Definition)?
From Gary Court:
I personally use .schema.json, but there is no official file
extension. The official mime type however is
"application/schema+json".
Update 2022Nov
application/schema+json and application/schema-instance+json will be published by an IETF RFC.
According to current proposal, both json and schema.json extensions are supported. I still find it quite inconvenient for processing based on conventions to have a dot within an extension.
Previous comment
According to the last draft (v4), there is not a new extension proposed for files storing json-schemas. .json extension is used profusely within that document. .json is also the preferred extension in validators (PHP, Ruby, Python).
So I think that .json should be the preferred option in absence of an official/standard new extension.
From https://json-schema.org/understanding-json-schema/basics.html#id3
Since JSON Schema is itself JSON, it’s not always easy to tell when
something is JSON Schema or just an arbitrary chunk of JSON. The
$schema keyword is used to declare that something is JSON Schema. It’s
generally good practice to include it, though it is not required.
So you can use .json as the file extension for JSON schema but maybe with a $schema keyword (although optional) for better distinction.
I've started using .jschema after I had a run-in with an extension-based JSON Schema parser that automatically added id's to external RAML examples which are also .json files.
They are a specific format, after all. HTML is XML, which is UML, and we use a different file extension for each of those.
My suggestion is .jsd or .jsonsd standing for Json Schema Document.
I followed the way XML Schemas are named XSD (Xml Schema Document)
A JSON Schema is a valid JSON file so the extension .json is OK.
Then, the first attribute of your file should be '$schema' to declare the version of the specification you are using. Eg.
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
Is there an existing program that helps forming a JSON Schema?
There's this great tool to get you started on generating a JSON Schema: http://www.jsonschema.net/ . Just feed a sample JSON files and out comes out a JSON Schema that you can then tweak.
Check this demo one. It is at an early stage but you can already edit jSON documents with a schema constraint as well as design a Schema itself.
And here is an official thread about Schema-based JSON editor:
You can use Orderly. They have DSL for schema description and you can try it online.
You could try this one (XML ValidatorBuddy) which is actually an XML editor but it also supports JSON and especially JSON Schema editing. The editor is a Windows desktop application and can do auto-completion and syntax-coloring for JSON schema files. You can also validate your JSON files against JSON schema.
You can do this in Liquid XML Studio, but its a commercial product
This isn't exactly something that'll help you with a 'schema', per se, but it's a visual way to navigate and manage JSON data.
http://braincast.nl/samples/jsoneditor/