Home > Mobile >  Fail Files that have no value stored using JSON Schema file
Fail Files that have no value stored using JSON Schema file

Time:10-24

I have code that validates .json files using a schema file. I'm trying to validate a list of values. But if the file has a "NO_DATA", "EMPTY", or "NULL" stored as a value, I want Splunk_Status = Data_JSON.IsValid(Schema) to be false.

Schema file I have so far:

"MN": {
    "Type": "string",
    "pattern": "[A-Z0-9]{14}",
},

File to fail:

{
  "MN": "NO_DATA",
}

File to pass (It doesn't have to have the exact pattern it just needs to not be empty):

{
"MN": "FS40-SR20D4-2C00W",
}

VB.net code:

schemaConn = ConfigurationManager.ConnectionStrings("LOCAL_SPLUNK_SCHEMA_PATH")
schema_path = schemaConn.ToString
            Schema_String = My.Computer.FileSystem.ReadAllText(schema_path)
extra_str = backup_path
Schema = JsonSchema.Parse(Schema_String)
step_str = "Validate JSON File Data Using Schema"
Data_String = My.Computer.FileSystem.ReadAllText(Splunk_Info.FullName)
Data_JSON = JObject.Parse(Data_String)
Splunk_Status = Data_JSON.IsValid(Schema)
System.Threading.Thread.Sleep(1000)
Console.WriteLine("SPLUNK VALIDATE: "   Splunk_Status.ToString)
If Splunk_Status = True Then
    File_Validation = True
    Console.WriteLine("File Location = "   Splunk_Info.FullName)
    GoTo Jump_ValidateHeader
Else
    File_Validation = False
    GoTo Jump_ValidateHeader
End If

CodePudding user response:

You can prohibit certain values by combining the not and enum keywords:

"not": {
  "enum": [ "NO_DATA", "EMPTY", "NULL" ]
}

You can read about these keywords here:

  • Related