JSON Schema - How to define dependencies between properties located in different files? - json

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.

Related

vs code ui editor for json schemas

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.

How can I use any json or array or any js file in .testcaferc.json?

I have created one file .testcaferc.json that contains all configuration information like browser name, specs, timeouts etc. I want to fetch the configuration data from file so that I have to change the information at only one place
I want to store all these information in single file, I tried, js, json and array. But I can not import all above format files in my .testcaferc.json, when I press Alt+F8 I see the error "Expected a JSON object, array or literal"
Is there any way I can import json, array or js data in .testcaferc.json?
Thanks in advance!!
The JSON format doesn't support any import directives. The TestCafe configuration file (.testcaferc.json) is a simple JSON file. So, the TestCafe configuration file doesn't support such functionality.
To achieve your goal, you can transform the existing .testcaferc.json file before test running: load data from various sources and add/replace values for the appropriate data fields.
Also, there is a suggestion in the TestCafe GitHub repository, which will make your scenario easier to implement. Track it to be notified about its progress.

How to set a schema in `node_modules` as a `$schema`

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.

AWS Glue Crawler Classifies json file as UNKNOWN

I'm working on an ETL job that will ingest JSON files into a RDS staging table. The crawler I've configured classifies JSON files without issue as long as they are under 1MB in size. If I minify a file (instead of pretty print) it will classify the file without issue if the result is under 1MB.
I'm having trouble coming up with a workaround. I tried converting the JSON to BSON or GZIPing the JSON file but it is still classified as UNKNOWN.
Has anyone else run into this issue? Is there a better way to do this?
I have two json files which are 42mb and 16mb, partitioned on S3 as path:
s3://bucket/stg/year/month/_0.json
s3://bucket/stg/year/month/_1.json
I had the same problem as you, crawler classification as UNKNOWN.
I were able to solved it:
You must create custom classifier with jsonPath as "$[*]" then create new crawler with the classifier.
Run your new crawler with the data on S3 and proper schema will be created.
DO NOT update your current crawler with the classifier as it won't apply the change, I don't know why, maybe because of classifier versioning AWS mentioned in their documents. Create new crawler make them work
As mentioned in
https://docs.aws.amazon.com/glue/latest/dg/custom-classifier.html#custom-classifier-json
When you run a crawler using the built-in JSON classifier, the entire file is used to define the schema. Because you don’t specify a JSON path, the crawler treats the data as one object, that is, just an array.
That is something which Dung also pointed out in his answer.
Please also note that file encoding can lead to JSON being classified as UNKNOWN. Please try and re-encode the file as UTF-8.

Configuring Object Instances from JSON in conf Files

So I want to be able to basically make instances of a class from JSON definitions in a conf file. In looking through the docs, I found that there are ways to reference things that are defined in JSON structures, but I was wondering about how best to instantiate objects from such definitions. For instance, suppose I had a class called RemoteRepository with 4 or 5 properties. I'd like to make a bunch of entries in a JSON file then read in at startup and get back a collection of RemoteRepository objects. I could do this with a database, of course, including a graph one, but would like to just do JSON if possible.
Assuming a static class definition that represents the JSON structure is acceptable, you can try the JSON C# Class Generator
Once you've generated your classes you can simply create a new instance or array of instances by passing in the json to the constructor that this tool creates on the generated class(es).
So I can make instances, but as usual, once I need a bunch of instances, it's time for a database. In this case, I ended up doing some simple XML files to trigger these instances. As much of a mess as XML is, for things like this, it does work best. Namely:
Some nesting of instance information
Not an exact mapping to the target class, e.g. field mappings are part of my config. I am going to load a few fields from the config file, but then create instances of a different class, hence the immediate conversion to a java class I would get from JSON is not meaningful
One other thing I figured out in doing this is that processing XML in Java is still kind of a mess. Still, this was the right way to go in this case.