Azure Data Factory Expression to Check if Property is Defined - json

I am working with JSON structured data in ADF and trying to implement an IF condition where, if a property is defined in JSON, I will execute one path, another if not defined.
For example, consider the JSON data:
{
"name" : "sh"
"RareProperty" : "rarevalue"
}
RareProperty may or may not exist depending on scenario.
If I try to reference RareProperty in the If Condition block, I get an error saying property RareProperty not defined, which is understandable as the property isn't actually defined in the scenario.
I am looking for a way to check if a property is defined without getting any error.

I think you can use the ? something like
#{body('yourresponse')?['RareProperty']}

Related

Deserialize an anonymous JSON array?

I got an anonymous array which I want to deserialize, here the example of the first array object
[
{ "time":"08:55:54",
"date":"2016-05-27",
"timestamp":1464332154807,
"level":3,
"message":"registerResourcePath ('', '/sap/bc/ui5_ui5/ui2/ushell/resources/')",
"details":"","component":"sap.ui.ModuleSystem"},
{"time":"08:55:54","date":"2016-05-27","timestamp":1464332154808,"level":3,"message":"URL prefixes set to:","details":"","component":"sap.ui.ModuleSystem"},
{"time":"08:55:54","date":"2016-05-27","timestamp":1464332154808,"level":3,"message":" (default) : /sap/bc/ui5_ui5/ui2/ushell/resources/","details":"","component":"sap.ui.ModuleSystem"}
]
I tried deserializing using CL_TREX_JSON_SERIALIZER, but it is corrupt and does not work with my JSON, here is why
Then I tried /UI2/CL_JSON, but it needs a "structure" that perfectly fits the object given by the JSON Object. "Structure" means in my case an internal table of objects with the attributes time, date, timestamp, level, messageanddetails. And there was the problem: it does not properly handle references and uses class description to describe the field assigned to the field-symbol. Since I can not have a list of objects but only a list of references to objects that solution also doesn't works.
As a third attempt I tried with the CALL TRANSFORMATION as described by Horst Keller, but with this method I was not able to read in an anonymous array, and here is why
My major points:
I do not want to change the JSON, since that is what I get from sap.ui.log
I prefere to use built-in functionality and not a thirdparty framework
Your problem comes out not from the anonymity of array, but from the awkwardness of SAP JSON (De)serializer, which doesn't respect double quotes, which enclose JSON attributes. The issue is thoroughly described in this answer.
If you don't want to change your JSON on-the-fly, the only way you have is to change CL_TREX_JSON_DESERIALIZER class like this.
/UI5/CL_JSON_PARSER parses JSONs with unknown format.
Note that it's got "for internal use" written on it so many times that you probably should take it seriously and clone its code to fixate it.

Store JSON object directly in MongoDB using Meteor

I'm tring my hand in Meteor - so far, I like it :-)
However, I am trying to store a JSON object directly into miniMongo, but not getting anywhere - while I thought that was the purpose :-)
testVar = {"test":"this is from the object"}
QStore.update(
{"_id" : QT._id},
{
$set: {
"tCode" : testVar,
"name" : "verion 6"
}
}
)
in the schema of the QStore, tCode is defined as {object} which I thought would be right... where am I wrong? :-)
regards,
Paul
Assuming you're using aldeed:simple-schema and everything else is okay (which is tough to tell with only the code snippet above), it's most likely you're missing the blackbox flag in your schema definition:
blackbox
If you have a key with type Object, the properties of the object will be validated as well, so you must define all allowed properties in the schema. If this is not possible or you don't care to validate the object's properties, use the blackbox: true option to skip validation for everything within the object.

SoapUI - how to assert a JSON element containing a custom property

I use SoapUI NG Pro (ReadyAPI-1.1.0.) and try to use the UI to set all my required assertions.
What I try to do is to check if a list (JSON) contains an element that is defined in a soapUI custom property. To get all elements from the list I use the path: $.devices[*].deviceName. Now I like to check if the string from the customer property ${#Project#devname.1} is part of the list.
To write the assertion I found two possibilities, but both of them do not really work.
Use JsonPath Match: The menu servers an input field for the path and one for the expected result and a check box named “Allow Wild…”. I filled the path with $.devices[*].deviceName and the expected result with ${#Project#devname.1}. I also checked the check box to support wildcards. The result is a positive assertion. SoapUI does what I expect. BUT! If I save the project and reopen it, the check box is not checked any more. I have to go over all my assertions and check the boxes again. This is not a solution because I have about 100 of these assertions.
Use JsonPath RegEx Match: A nice way not use the broken “Allow Wild…” checkboxes should be to use a regular expression instead. Therefore I use the “JsonPath RegEx Match” and put the right path $.devices[*].deviceName into the input field and used this regular expression: ${#Project#devname.1}. Sadly this does not work, because SoapUI does not expand the Custom Properties before applying the regular expression. I did not find anything in the documentation explaining how to use custom properties in regular expressions. Could you help here?
In any case. What is a good solution for this type of assertions?
You can try to use JsonPath Match assertion with expression
$.devices[?(#.deviceName=='${#Project#devname.1}')].deviceName.
It will try to find device with deviceName == devname.1. If exists = true, if not - "Comparison failed for path "...", expecting [%your deviceName%], actual was [[]]"

Neo4j node property containing raw json as metadata

Is this possible to have a node property as json raw string and to filter on it with cypher ?
I have a node with some defined properties and metadata (json raw string).
I would like to select or filter on those metadata property.
This is something like this :
START movie=node:TYPE_INDEX(Type = 'MOVIE') // Start with the reference
MATCH movie-[t:TAG]->tag
WHERE collect(movie.Metadata).RatingPress > 3
RETURN distinct movie.Label
And metadata are something like this :
{"RatingPress" : "0","RatingSpectator" : 3"}
I have expected to use collect function in order to call the property like this :
collect(movie.Metadata).RatingPress
But, of course it fails...
Is this a way to bind some json string from a node property with cypher ?
Thanks for your help
That's going against the principles of properties. Why not set the properties in the JSON metadata directly on the node?
But to answer your question:
No, cypher has no knowledge about JSON.
We treat the entire Node as a JSON blob. Since Neo4j doesn't support hierarchical properties, we flatten out the JSON into delimited property names on save and unflatten them on read. You can then form Cypher queries on (for example) property name "foo.bar.baz". The queries tend to look a bit funky because you'll need to quote them using single back quotes, but it works.

Grails, create domain object from json-string with has-many relation

I'm trying to parse a grails parameter map to a Json String, and then back to a parameter map. (For saving html form entries with constraint-violations)
Everything is fine as long as there is no hasMany relationship in the parameter-map.
I'm using
fc.parameter = params as JSON
to save the params as JSON String.
Later I'm trying to rebuild the parameter map and create a new Domain-Object with it:
new Foo(JSON.parse(fc.parameter))
Everything is fine using only 1:1 relationships (states).
[states:2, listSize:50, name:TestFilter]
But when I try to rebuild a params-map with multi-select values (states)
[states:[1,2], listSize:50, name:TestFilter]
I'm getting this IllegalStateException:
Failed to convert property value of type org.codehaus.groovy.grails.web.json.JSONArray to required type java.util.Set for property states; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [de.gotosec.approve.State] for property states[0]: no matching editors or conversion strategy found
I tried to use this, but without success:
JSON.use("deep") {
new Foo(JSON.parse(fc.parameter))
}
You can use JsonSlurper instead of the converters.JSON of grails, it maps JSON objects to Groovy Maps. I think this link also might help you.
Edit: Now, if the problem is binding the params map to your domain, you should try using bindData() method, like:
bindData(foo, params)
Note that this straightforward use is only if you're calling bindData inside a controller.
What seems to be happening in your case is that Grails is trying to bind a concrete type of List (ArrayList in the case of JsonSlurper and JSONArray in the case of converters.JSON) into a Set of properties (which is the default data structure for one-to-many associations). I would have to take a look at your code to confirm that. But, as you did substitute states: [1,2] for a method of your app, try another test to confirm this hypothesis. Change:
states:[1,2]
for
states:[1,2] as Set
If this is really the problem and not even bindData() works, take a look at this for a harder way to make it work using object marshalling and converters.JSON. I don't know if it's practical for you to use it in your project, but it sure works nicely ;)