JSONPath concat arrays and joing - jsonpath

I am trying to use JSONPath expression to extract 2 arrays and concatenate them today to form a long array - and ideally making them unique. However, no syntax I use in the online playground produces results. Ultimately I will want to use this in a Jenkins job. So, it has to be operational with the Java implementation
Here is my json
{
"commits": [
{
"author": {
"name": "Christian",
"email": "christian#company.com"
},
"added": [
"deleteme/main.tf"
],
"modified": [
],
"removed": [
"deleteme.txt"
]
}
]
}
And here is my expression (which I am trying to evaluate here):
$.append($.commits[*].added[*], $.commits[*].removed[*])
Which I would love to see as
["deleteme/main.tf", "deleteme.txt"]
Or better still:
"deleteme/main.tf, deleteme.txt"
because ultimately I need a comma separated set of values
Oh yeah: Bonus for only unique results

JSON Path is a query language. Some tools have used it to enable transformation functionality, but this is not something that JSON Path itself generally supports.
Disclaimer and Open Specification Plug
The online tool you linked is not "official." There is no "official" tooling because there is no specification. Pretty much everyone has been building implementations from a 15yo blog post and adding their own features.
But there's good news: we're building a spec!

Related

Choosing the right name for properties in schema for Weaviate

When loading my schema into Weaviate, I get an error message that the property name can not be found in the contextionary. Some of the properties I need are abbreviations.
This is the schema item it is complaining about:
{
"cardinality": "atMostOne",
"dataType": [
"boolean"
],
"description": "Is this a BLWS elbow yes or no",
"keywords": [
{
"keyword": "BLWS",
"weight": 1
}
],
"name": "blws"
}
This is the error message I get:
2019-09-04T11:47:07.202646 ERROR: {'error': [{'message': "Could not
find the word 'blws' from the property 'blws' in the class name
'Elbow' in the contextionary. Consider using keywords to define the
semantic meaning of this class."}]}
The misleading error
The error message
Consider using keywords to define the semantic meaning of this class
is outdated and and the recommendation in fact not helpful. There is already a GitHub issue to clean this up: https://github.com/semi-technologies/weaviate/issues/929
Prior to https://github.com/semi-technologies/weaviate/issues/856 it was possible to replace an unknown property word with known keywords, but #856 removed that possibility.
However, even prior to the change your schema would not have been accepted, see below.
About property names which are not in the contextionary
A property name consist of one or more recognized parts which is known by the contextionary. By "part" I mean that if you combine multiple words using camelCasing each word would be one part. So for example
drivesVehicle would be valid as it consists of two known words: drives, vehicle
drivesAVehicle would also be valid, as it contains two known words and a stop word (a). Note: Stopwords are fine as long as your property contains at least one non-stopword.
drivesBlws would be invalid, as blws is not a known word
We have discussed adding an ability to add custom words. The proposal can be considered accepted, but at the time of this writing it is not in immediate prioritization.
Why so strict about known words?
One of the core functionalities of weaviate is concept searching ("vector-based searching"), so weaviate must be able to calculate a vector position for each property. It can only do that if it recognizes the words
How to solve this?
Try describing a "blws" with known words. For example if "blws" was an acronoym for "bold long wide short", you could name the property boldLongWideShort. As mentioned above, we will add the ability to add custom words in the future, but as of now that's not supported yet.

Using parameters in Azure Service Bus Subscription SqlFilter expression

I am using an ARM template to try and deploy a subscription to an Azure Service Bus Topic which filters messages based on the To system property. I would like to pull the value for the filter from an ARM template parameter, but I can't seem to get the template to resolve the param in the SqlExpression.
Below is the template I have been messing around with. I thought I could maybe just toggle the requiresPreprocessing switch to get it to resolve the param on deployment, but no dice. I also played with trying to escape it using double square brackets or colons as shown in the link below
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-sql-filter#propertyname
{
"apiVersion": "2017-04-01",
"name": "[concat(parameters('mynamespace'), '/', parameters('topic'), '/', parameters('myVariable'),'/direct')]",
"type": "Microsoft.ServiceBus/namespaces/topics/subscriptions/rules",
"dependsOn": [
"[resourceId('Microsoft.ServiceBus/namespaces', parameters('mynamespace'))]",
"[resourceId('Microsoft.ServiceBus/namespaces/topics', parameters('mynamespace'), parameters('topic'))]",
"[resourceId('Microsoft.ServiceBus/namespaces/topics/subscriptions', parameters('mynamespace'), parameters('topic'), parameters('myVariable'))]"
],
"properties": {
"filterType": "SqlFilter",
"sqlFilter": {
"sqlExpression": "sys.To=[parameters('myVariable')] OR sys.To IS NULL",
"requiresPreprocessing": true
}
}
What I am getting is the string exactly as it is displayed in the sqlExpression, but I would like to get the value that the variable resolves to in a single quoted string.
This topic subscription rules may only get static values. Maybe you can try with a static value instead of [parameters('myVariable')]. This problem might because of giving dynamic value to the property sys.To.
You could use: "[concat('sys.To=',[parameters('myVariable')],' OR sys.To IS NULL')]".
You cannot use inline expressions in an ARM template I think, therefor you should make the whole thing an expression and in this case use concat to glue the parts together.
Hint: including single quotes is difficult, so a variable like this might come in handy:
"SQ": "'"

What is the best way to get the .cs file from a given .proto file with protobuf.net

After several trial with the protobuf.net online generator, I doubt of the way y use to get the more relevant .cs file from an .proto file.
The Input proto file is the sparkplub_b file from link below:
https://github.com/Cirrus-Link/Sparkplug/blob/master/sparkplug_b/sparkplug_b.proto
In Sparkplug documentation the Datatype enums have the string form 'Uint64', and in the result .cs file we have ‘LongValue’.
(I have also to do some changes in the .cs file to be able to use enums with the 'DataType' in the JSON serialization of the object instance)
Thank you.
"Timestamp": 1538568112852,
"Metrics": [
{
"Name": "bdSeq",
"Timestamp": 1538568112852,
"Datatype": 4,
"IsNull": false,
"Metadata": null,
"Properties": null,
"LongValue": 0,
"ValueCase": 11
}
],
"Seq": 18446744073709551615
}
Sorry for delay, I was taking some time off. I'm the protobuf-net author.
What is the best way to get the .cs file from a given .proto file with protobuf.net
Ultimately, for protobuf-net specifically: protogen - which is what https://protogen.marcgravell.com/ uses (I assume that's what you were talking about when you say "with the protobuf.net online generator")
In Sparkplug documentation the Datatype enums have the string form 'Uint64', and in the result .cs file we have ‘LongValue’.
I assume that is coming from:
uint64 long_value = 4;
If the concern is the naming (LongValue vs long_value), then note that protobuf-net has options to allow more control over this; LongValue is just the default convention.
However: this isn't an enum - there is no enum in sparkplug_b.proto. If you can be more specific about what you want to get as the generated code (and ideally, why), I can almost certainly help more.
(edit: there is an enum optionally generated from the oneof)

How to store Map in Solr document?

I am trying to add HashMap into Solr document. I have gone through Solr documentation but didn't get exactly what I am trying to do.
Solr supports list but I need Map stored in document.
Example:
{
"id": "123456",
"name": "Foo bar",
"social":{
"facebook":"facebookid",
"twitter":"twitterid"
}
}
The easiest way is to flatten the structure before indexing it, as that will make queries, facets and most other features easier to use (as you won't have to use any blockjoins, child/parent-support, etc.).
Index the content as:
{
"id": "123456",
"name": "Foo bar",
"social_facebook": "facebookid",
"social_twitter": "twitterid"
}
.. and recreate the map if necessary (it usually isn't) in your query layer (which would vary depending on the language and library you're using).

Filter property based searches in Artifactory

I'm looking to use the Artifactory property search
https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-ArtifactSearch%28QuickSearch%29
Currently this will pull json listing any artifact that matches my properties.
"results" : [
{
"uri": "http://localhost:8080/artifactory/api/storage/libs-release-local/org/acme/lib/ver/lib-ver.pom"
},{
"uri": "http://localhost:8080/artifactory/api/storage/libs-release-local/org/acme/lib/ver2/lib-ver2.pom"
}
]
I need to be able to filter the artifacts I get back as i'm only interested in a certain classifier. The GAVC Search has this with &c=classifier
I can do it in code if this isn't possible via the interface
Any help appreciated
Since the release of AQL in Artifactory 3.5, it's now the official and the preferred way to find artifacts.
Here's an example similar to your needs:
items.find
(
{
"$and":[
{"#license":{"$eq":"GPL"}},
{"#version":{"$match":"1.1.*"}},
{"name":{"$match":"*.jar"}}
]
}
)
To run the query in Artifactory, copy the query to a file and name it aql.query
Run the following command from the directory that contains the aql.query file
curl -X POST -uUSER:PASSWORD 'http://HOST:PORT/artifactory/api/search/aql' -Taql.query
Don't forget to replace the templates (USER, PASSWORD,HOST and PORT) to real values.
In the example
The first two criteria are used to filter items by properties.
The third criteria filters items by the artifact name (in our case the artifact name should end with .jar)
For more details on how to write AQL query are in AQL
Old answer
Currently you can't combine the property search with GAVC search.
So you have two options:
Executing one of them (whichever gives you more precise results) and then filter the JSON list on the client by a script
Writing an execution user plugin that will execute the search by using the Searches service and then filter the results on the server side.
Of course, the later is preferable.

Resources