JsonSchema definition for either or value - json

I am writing a JSON schema for helm chart values.yaml wherein the yaml file is as follows:
accessID: "" // user set this value when installing individual chart
global:
accessID: "" // user set this when installing the parent which this chart is part of
How can I write JSON schema (version 7) to validate either one of this should have a non empty string.

You'll want to use an anyOf wrapped around the checks for either property. Exact matches can be done with const.
https://json-schema.org/understanding-json-schema/reference/conditionals.html
https://json-schema.org/understanding-json-schema/reference/generic.html#constant-values
https://json-schema.org/understanding-json-schema/reference/object.html

Related

Extract a specified data object that resides inside a PDF form field to an external file

I am looking for a script to extract a data object nested inside a data object to a new data object. Aside from being able to easily clone the object by creating a new one, while I can also extract one of several objects nested inside an object that includes all its related properties and values, the name associated with the property and values is missing. Hence, I require a script to create a new object containing any one of several names including its related properties and values extracted from the existing object provided below.
{"J Doe Company":{"lastUpdate":"01/05/2023","website":"jdoecompany.com","userID":"jdoe1985#gmail.com","password":"igfndhsi1985","primaryCC":"Discover","secondaryCC":"Capital One","primaryBank":"Chase","secondaryBank":"","sq1":"Year Graduated HS","sa1":"1985","sq2":"","sa2":"","notes1":"Sample password record","notes2":""},"Bob The Builder":{"lastUpdate":"01/05/2023","website":"bobthebuilder.com","userID":"bobthebuilder#gmail.com","password":"bbob1985","primaryCC":"Amazon Visa","secondaryCC":"Mastercard","primaryBank":"Wells Fargo","secondaryBank":"","sq1":"First Girlfriend's Name","sa1":"Kaye","sq2":"","sa2":"","notes1":"Sample password record","notes2":""},"SpongeBob Square Pants":{"lastUpdate":"01/07/2023","website":"spongebobsquarepants.com","userID":"spongebob#gmail.com","password":"spongebob1999","primaryCC":"None/Not Applicable","secondaryCC":"","primaryBank":"None/Not Applicable","secondaryBank":"","sq1":"Year show debuted on TV","sa1":"1999","sq2":"","sa2":"","notes1":"Animated TV show for kids","notes2":""}}
You can run cpdf -output-json in.pdf -o put.json and process the result. The format is described in the cpdf manual.
Upon further trial and error after learning more about how to create and edit an object literal, the script required to add an object along with its key-value properties is as follows:
dsFld =getField("dataSrc");// dataSRC is a hidden field containing a JS object converted to a JSON string
oVendors = JSON.parse(dsFld.value); // oVendors is a JS object
oVendors[event.value]=oVendorsPropValues;//oVendorsPropValues = {key-value pairs}
dsFld.value = JSON.stringify(oVendors);// convert the JS obj back to a JSON string

Azure DevOps Pipeline Json Variable Substitution - Microsoft.Hosting.Lifetime

How can I change the value of Logging:LogLevel:Microsoft.Hosting.Lifetime using a Json Variable Substitution task in Azure DevOps?
This article...
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=azure-devops&tabs=Classic
...states:
If a variable name includes periods ("."), the transformation will attempt to locate the item within the hierarchy. For example, if the variable name is first.second.third, the transformation process will search for:
"first" : {
"second": {
"third" : "value"
}
}
as well as "first.second.third" : "value".
Neither of these would be able to target a nested value with periods (.) in the name? Right?
Neither of these would be able to target a nested value with periods
(.) in the name? Right?
Sorry but I'm afraid you can't be able to do that with JSON variable substitution for now. The official document has stated that the JSON variable substitution option doesn't support variables whose names contain periods. It's not supported by design, and it's already documented in the Notes.
As alternative workarounds:
You can define the variable name in another format, something like Logging:LogLevel:Microsoft_Hosting_Lifetime.
Try using Replace Token task to change the value of Logging:LogLevel:Microsoft.Hosting.Lifetime. This task should work for your scenario. For more details you can check this issue.
Also you can submit a feature request about JSON variable substitution option on our UserVoice site, which is our main forum for product suggestions. The product team would provide the updates if they view it. Thank you for helping us build a better Azure DevOps.

Azure | ADF | How to use a String variable to lookup a Key in an Object type Parameter and retrieve its Value

I am using Azure Data Factory. I'm trying to use a String variable to lookup a Key in a JSON array and retrieve its Value. I can't seem to figure out how to do this in ADF.
Details:
I have defined a Pipeline Parameter named "obj", type "Object" and content:
{"values":{"key1":"value1","key2":"value2"}}
Parameter definition
I need to use this pipeline to find a value named "key1" and return it as "value1"; "key2" and return it as "value2"... and so on. I'm planning to use my "obj" as a dictionary, to accomplish this.
Technically speaking, If i want to find the value for key2, I can use the code below, and it will be returned "value2":
#pipeline().parameters.obj.values.key2
What i can't figure out is how to do it using a variable (instead of hardcoded "key2").
To clear things out: I have a for-loop and, inside it, i have just a copy activity: for-each contents
The purpose of the copy activity is to copy the file named item().name, but save it in ADLS as whatever item().name translates to, according to "obj"
This is how the for-loop could be built, using Python: python-for-loop
In ADF, I tried a lot of things (using concat, replace...), but none worked. The simpliest woult be this:
#pipeline().parameters.obj.values.item().name
but it throws the following error:
{"code":"BadRequest","message":"ErrorCode=InvalidTemplate, ErrorMessage=Unable to parse expression 'pipeline().parameters.obj.values.item().name'","target":"pipeline/name_of_the_pipeline/runid/run_id","details":null,"error":null}
So, can you please give any ideas how to define my expression?
I feel this must be really obvious, but I'm not getting there.....
Thanks.
Hello fellow Pythonista!
The solution in ADF is actually to reference just as you would in Python by enclosing the 'variable' in square brackets.
I created a pipeline with a parameter obj like yours
and, as a demo, the pipeline has a single Set Variable activity that got the value for key2 into a variable.
This is documented but you need X-ray vision to spot it here.
Based on your comments, this is the output of a Filter activity. The Filter activity's output is an object that contains an array named value, so you need to iterate over the "output.value":
Inside the ForEach you reference the name of the item using "item().name":
EDIT BASED ON MORE INFORMATION:
The task is to now take the #item().name value and use it as a dynamic property name against a JSON array. This is a bit of a challenge given the limited nature of the Pipeline Expression Language (PEL). Array elements in PEL can only be referenced by their index value, so to do this kind of complex lookup you will need to loop over the array and do some string parsing. Since you are already inside a FOR loop, and nested FOR loops are not supported, you will need to execute another pipeline to handle this process AND the Copy activity. Warning: this gets ugly, but works.
Child Pipeline
Define a pipeline with two parameters, one for the values array and one for the item().name:
When you execute the child pipeline, pass #pipeline.parameters.obj.values as "valuesArray" and #item().name as "keyValue".
You will need several string parsing operations, so create some string variables in the Pipeline:
In the Child Pipeline, add a ForEach activity. Check the Sequential box and set the Items to the valuesArray parameter:
Inside the ForEach, start by cleaning up the current item and storing it as a variable to make it a little easier to consume.
Parse the object key out of the variable [this is where it starts to get a little ugly]:
Add an IF condition to test the value of the current key to the keyValue parameter:
Add an activity to the TRUE condition that parses the value into a variable [gets really ugly here]:
Meanwhile, back at the Pipeline
At this point, after the ForEach, you will have a variable (IterationValue) that contains the correct value from your original array:
Now that you have this value, you can use that variable as a DataSet parameter in the Copy activity.

VSTS JSON Variable Substitution with Default Release Variables

TL; DR
Is there any way that I can use JSON variable substitution with default Release variables in VSTS?
Description
With VSTS, I can use JSON variable substitution to set values in an appsettings.json file at release time. For example, with an appsettings.json file that looks like this:
{
"ConnectionStrings": {
"DM_ADJ": "placeholder",
"DM_SALES": "placeholder"
},
// And so on. Placeholders get replaced
}
I can define a Release variable in VSTS called ConnectionStrings.DM_ADJ, and the value I provide there will replace "placeholder" in the corresponding JSON line.
Now, I would also like to use some of the default Release variables in my app's configuration. For example, there are default Release variables called Release.DefinitionName and Release.DefinitionId. I thought that I could substitute them into an appsettings.json config section like below, but unfortunately, when the Release completes, the "placeholder" strings do not get replaced. Am I missing something?
{
"Release": {
"DefinitionName": "placeholder",
"DefinitionId": "placeholder",
}
// And so on. Placeholders do not get replaced
}
This is an expected behavior since it excludes the build/release's system definition variables:
If you want to use the system definition variables in the json file, creating a custom variable and set the value to system defined variable like following instead of using system defined variable directly:
you need to specify the json file you want to change the values
then you just need to create a variable with the path you want to change.
for example i want to change the property Version
so, i need to create a variable with this name:
Aplicacao.Version

Return empty array when transforming xml data to json

I am returning some xml structure as json using the built-in MarkLogic json module. For the most part it does what I expect. However, when an element marked as an array is empty, it returns an empty string instead of an empty array. Here is an example:
xquery version "1.0-ml";
import module namespace json = "http://marklogic.com/xdmp/json"
at "/MarkLogic/json/json.xqy";
let $config := json:config("custom")
return (
map:put( $config, "array-element-names", ("item") ),
json:transform-to-json(<result>
<item>21</item>
<item>22</item>
<item>23</item>
</result>, $config),
json:transform-to-json(<result></result>, $config))
Result:
{"result":{"item":["21", "22", "23"]}}
{"result":""}
I would expect an empty array if there were no items matching in the array-element-name called "item". i.e.
{"result":{"item":[]}}
Is there some way to configure it so it knows the element is required ?
No - it will not create anything that is not there. In your case, what if the XML was more complex. There is no context of 'where' such an element might live - so it could not create it even if it wanted to.
Solution is to repair the content if needed by adding one element - or transforming it into the json-basic namespace - where those elements live inside of of an element noted as an array (which can be empty) - or third, use an XSD to hint to the processor what to do . But that would still need a containing element for the 'array' - and then the items would be minOccurance=0. But if this is the case, then repair and transform into the json/basic namespace is probably nice and simple for your example.