Would like to allow null on an optional date property where the date format is validated with a regex expression. Is this even possible?
"dateOfRetirement": {
"description": "Optional. Format: yyyy-MM-dd.",
"type": ["string", "null"],
"pattern": "^\\d{4}-\\d{2}-\\d{2}$"
}
To get the regular syntax for that you have to add a condition to your regex.
Your regex will get (assuming your regex syntax has no error!):
^(\\d{4}-\\d{2}-\\d{2}|null)$
Steps done:
incapsulate the normal regex with brackets (())
add an or-operator to the regex (|)
add the second validation for null to the regex after the or-operator
In the end the regex will allow a-valid-date-format or null as text.
I don't think that will work when "column": null.
It will only account for "column": "null" in regex
Related
I have the following html code:
'"height": { "#type": "QuantitativeValue", "value": "6-1" },\n
"weight": {"#type": "QuantitativeValue", "value": "195 lbs" }\n}\n'
I want to create a Regex that'll extract the height and weight values (6-1 and 195 lbs). What re expression can do this?
If you don't have anything else with the pattern "value": "", then just use:
value":\s"?(.*)"
https://regex101.com/r/clWVkg/1
If you do, then you can specify that you only want the values from height and weight caught:
(height|weight).*"value":\s"?(.*)"
https://regex101.com/r/5ShdKO/1
This will check for the word height or weight first, then ignore everything until value before doing a lazy catch all to capture the value. You should be able to extract the value by extracting the group.
For example, need to validate field GRADE - not blank string (which can be converted to integer) or integer between 1 and 1000
The most basic definition would be:
"GRADE": {
"type": ["string", "integer"],
"pattern": "^[0-9]+$"
}
Take a look at the pattern keyword as described in detail here: https://json-schema.org/understanding-json-schema/reference/string.html#id6
You can define a regular expression that meets your exact requirements for the GRADE field.
Is there a way to get the value from key "· gc.alloc.rate"? Because the standard reference name after the dot returns an error.
...
"secondaryMetrics": {
"·gc.alloc.rate": {
"score": 502.22945873992126,
"scoreError": "NaN",
"scoreConfidence": [
"NaN",
"NaN"
],
...
You can either escape the attribute name with backticks or forward ticks, or use the bracket notation and a quoted string:
secondaryMetrics.`·gc.alloc.rate`
secondaryMetrics.´·gc.alloc.rate´
secondaryMetrics['·gc.alloc.rate']
secondaryMetrics["·gc.alloc.rate"]
https://www.arangodb.com/docs/stable/aql/fundamentals-syntax.html#names
I have a structure like this:
{"payload": {
"Item1": {
"property1": "Sunday",
"property2": "suffering_8890"
},
"Item2": {
"property1": "Monday",
"property2": "misery_0776"
},
"Item3": {
"property1": "Tuesday",
"property2": "pain_6756"
}
}
}
I need the property2 value that contains a certain sub-string (i.e- "misery"). Ultimately I just need the 4-digit code, but even getting the full value will work. I am able to get a list of all the property2 values by using:
$..property2
This returns:
Result[0] = suffering_8890
Result[1] = misery_0776
Result[2] = pain_6756
How do I filter it so that it only gives me the result containing the substring "misery"?
With regards to full value you can use a Filter Operator like:
$..[?(#.property2 =~ /misery.*?/i)].property2
Demo:
You can extract the 4-digit value out of the variable using Regular Expression Extractor
If you want to do this in one shot:
Add JSR223 PostProcessor as a child of the request which returns above JSON
Put the following code into "Script" area
vars.put('misery', ((com.jayway.jsonpath.JsonPath.read(prev.getResponseDataAsString(), '$..[?(#.property2 =~ /misery.*?/i)].property2').get(0) =~ ('(\\d+)'))[0][1]))
Refer the extracted value as ${misery} where required
More information: Apache Groovy - Why and How You Should Use It
You can use a regular expression extractor as well for the mentioned scenario to fetch the four-digit as below
property2": "misery_(.*)"
This will help you to save the four-digit code in JMeter variables right away. If you insist you to find out the required value from JSON using jsonpath, you can use JSON filter as below :-
$..[?(#.property2.indexOf('misery')>=0)]..property2
For example, I got following JSON from a URL
{ "time": "2014-05-10 06:23:36 UTC",
"values": [
{
"time_timetable_utc": "2014-05-10T06:25:00Z",
"time_realtime_utc": null,
"flags": ""
},
{
"time_timetable_utc": "2014-05-10T06:45:00Z",
"time_realtime_utc": null,
"flags": ""
},
]
}
This will work on YQL
select time from json where url="{url}"
It will return me only time field
{"time": "2014-05-10 06:23:36 UTC"}
But if I only want to get "values" array field with following
select values from json where url="{url}"
I will get this error message
Query syntax error(s) [line 1:7 expecting fields_or_star got 'values']
Just want to ask is that possible to select a JSON field whose name is a reserved Yahoo YQL keywords?
I know this will work
select * from json where url="{url}" and itemPath="json.values"
But is that possible to do it without using "itemPath" condition?
How to escape reserved word like "values" in YQL select?
Just want to ask is that possible to select a field names "values"?
No. (Sorry!)