I am getting the below Json Response by hitting a RestAPI.
**
[
{
"index": 0,
"object": {
"attributes": {
"ID": [
{
"type": "configuration/entityTypes/Customer/attributes/ID",
"ov": true,
"value": "5",
"uri": "entities/attributes/ID/2Cqf5xG2"
},
{
"type": "configuration/entityTypes/Customer/attributes/ID",
"ov": true,
"value": "3028",
"uri": "entities/attributes/ID/fto38ZRR"
}
],
"IgpId": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpId",
"ov": true,
"value": "1911",
"uri": "entities/attributes/IgpId/20ft8omYM"
}
],
"IgpName": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpName",
"ov": true,
"value": "Dr. heath",
"uri": "entities/attributes/IgpName/20ft8oe1q"
}
],
"IgpID": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpID",
"ov": true,
"value": "1872",
"uri": "entities/attributes/IgpID/20ft8oiI6"
}
],
"IgpNAME": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpNAME",
"ov": true,
"value": "Dr Jc crook",
"uri": "entities/attributes/IgpNAME/20ft8oqoc"
}
]
}
},
"successful": true
}
]
**
I am trying to save the values for CoachID (3028), IgpID(1872), IgpId(1911), IgpName(Dr. heath), IgpNAME(Dr Jc crook) in String variables in APex class.
I have used a map to do so but unable to get the proper values. I wanted to get the above values in a List & return that list from function.
Can anyone help me on this? I am not supposed to do this using wrapper.
Regards,
Mohit
It can't be done as straight "JSON.deserialize" call because some fields are reserved keywords in Apex. How strict the wrapper ban is? I wouldn't want to type this stuff freehand but you can go to https://json2apex.herokuapp.com/, tick checkbox about explicit parser (again, since you have reserved keywords it'd happen anyway) and well, you have a ready class & cool stab at unit test / example how to use the code. It's battle-tested, if you can't use that then your project has bigger problems ;)
If you really really have to do it alone and with maps it'll be something like https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm, example for deserializeUntyped
Related
I am using jsonpath to filter.
Json(Dummy json just to explain) source String, which is basically a list of Operating systems and details of its programs etc. In this example, the OS whose id = 1403 is a windows 10 OS and has 2 features acchritecture and browser. There are more details to the browser feature as shown in json
[
{
"id": 1403,
"os": "window 10",
"features": [
{
"id": 1356,
"name": "architecture",
"value": [
{
"id": 1308,
"feature": [
{
"id": 1262,
"key": "name",
"value": "amd64"
}
]
}
],
"category": "cat1"
},
{
"id": 1357,
"name": "browser",
"value": [
{
"id": 1309,
"feature": [
{
"id": 1263,
"key": "name",
"value": "Firefox"
},
{
"id": 1265,
"key": "version",
"value": "187"
}
]
}
],
"category": "cat2"
}
]
},
{
"id": 2804,
"os": "window 7",
"features": [
{
"id": 2764,
"name": "architecture",
"value": [
{
"id": 2719,
"feature": [
{
"id": 2679,
"key": "name",
"value": "amd64"
}
]
}
],
"category": "cat1"
},
{
"id": 2765,
"name": "browser",
"value": [
{
"id": 2722,
"feature": [
{
"id": 2685,
"key": "name",
"value": "Chrome"
},
{
"id": 2684,
"key": "version",
"value": "87.0.4280.88"
}
]
}
],
"category": "cat2"
}
]
}
]
I want to be able to filter the json such that
features[*].name == 'browser' and features[*].value[*].feature[*].value == 'chrome'
What will be the JsonPath string that can help me achieve above query? The above query uses similar syntax used by JsonPath string but doesn't do the job. Its just to explain.
There is another example here gets Movie Title Given 'Starring' field
And would like to get the full OS json that fulfils this condition. In this case a array of OS which contains only one OS i.e. with id= 2804
[
{
"id": "2804",
...
}
]
I am stuck much before what aim to achieve. Here is my code to get all the OS that have "name=browser". I get the array but it only contains value[] items. I want it get the full json. It returns object with IDs- 1357, 2765.
List<Map<String, Object>> expensive = JsonPath.parse(jsonDataSourceString)
.read("$[*].features[*].[?(#.name == 'browser')]");
To get the outer array you need to use the filter like $[?(...)]
For your current use case, we need to use nested array filters. There is an open issue in JsonPath for filter on children level. (Refer here).
Luckily, there is a workaround suggested to use contains over here.
we can use the below expression to filter:
List<Object> expensive = JsonPath.parse(jsonDataSourceString)
.read("$[?(#.features[?(#.name == 'browser')].value[*].feature[*].value contains 'Chrome')]");
Prints the below output
{id=2804, os=window 7, features=[{"id":2764,"name":"architecture","value":[{"id":2719,"feature":[{"id":2679,"key":"name","value":"amd64"}]}],"category":"cat1"},{"id":2765,"name":"browser","value":[{"id":2722,"feature":[{"id":2685,"key":"name","value":"Chrome"},{"id":2684,"key":"version","value":"87.0.4280.88"}]}],"category":"cat2"}]}
I am trying to submit an item to an API, the request goes through but comes back with an incorrect item construction returned by the API.
The code works compiles and runs without a problem, unfortunately the item constructed is incorrect.
API I am using: https://www.clover.com/api_docs/#!/inventory/CreateItem
If the above link does not work, navigate to Inventory -> Items -> Create an Inventory Item.
I have played around with what I am sending to the server but my problem is with the tags argument of the API. No matter what I set the "tags" field to, the returned item never has a tags field. I also have a UI that I can see all the item's properties. "tags" is always null.
Here is what I am feeding the API:
{
"name":"test_item_with_label",
"sku":"1234",
"code":"959",
"price":1698,
"tags":[
{
"id":"Z1JC35RHV6PFP",
"name":"Sewing",
"showInReporting":false
}
],
"priceType":"FIXED",
"defaultTaxRates":true,
"hidden":false,
"revenue":true
}
This is the item's properties after the request:
{
"id": "FCMS6MSAFYK1E",
"hidden": false,
"name": "test_item_with_label",
"code": "959",
"sku": "1234",
"price": 1698,
"priceType": "FIXED",
"defaultTaxRates": true,
"isRevenue": true,
"modifiedTime": 1564272103000
}
I want the item to be constructed correctly through the API with tags.
This is the available tags for reference.
"elements": [ {
"id": "Z1JC35RHV6PFP",
"name": "Sewing",
"showInReporting": false
}, {
"id": "STBVZXTVHDYK6",
"name": "Compass Industries",
"showInReporting": false
}, {
"id": "SSWR290EAK8RM",
"name": "Savor Jerky",
"showInReporting": false
}, {
"id": "GCENM7Y4RBJE2",
"name": "Triple K",
"showInReporting": false
}, {
"id": "E9H3YC70T4D6W",
"name": "Sabre/Security Equipment Co.",
"showInReporting": false
}, {
"id": "4ANVQMMFK7MNR",
"name": "Lansky Sharpeners",
"showInReporting": false
}, {
"id": "1H66V1ZK7Y84Y",
"name": "Nebo/ True Utility",
"showInReporting": false
}, {
"id": "0PZ5R8VV61QDJ",
"name": "Victorinox Swiss Army",
"showInReporting": false
}]
Found the answer!
Leaving it here in case anyone else runs into this problem with the Clover PoS API.
Basically their API is wrong! It says you can feed all those arguments in the docs, but you first must create the item THEN come back and tag the item with the correct tag by ID.
Answer found here: https://community.clover.com/questions/1822/can-somebody-tell-me-the-use-of-v3merchantsmidtag.html
Although my fields are visible in the discover tab, I can't make any kind of visualization with them and i got this message:
No results displayed because all values equal 0.
This is the data in the discover tab:
Visualise data result:
**index mappings:*
{
"mapping": {
"httpbeat": {
"_meta": {
"version": "5.2.1"
},
..........
"response": {
.....
"headers": {
"type": "nested",
"properties": {
"Content-Type": {
"type": "keyword",
"ignore_above": 1024
},
"Date": {
"type": "keyword",
"ignore_above": 1024
},
"X-Application-Context": {
"type": "keyword",
"ignore_above": 1024
}
}
},
"jsonBody": {
"type": "nested",
"properties": {
"classes": {
"type": "long"
},
"classes_loaded": {
"type": "long"
},
"classes_unloaded": {
"type": "long"
},
"counter_status_200_health": {
"type": "long"
},
"counter_status_200_login": {
"type": "long"
},
"counter_status_200_metrics": {
"type": "long"
},
"counter_status_302_unmapped": {
"type": "long"
},
"gauge_response_health": {
"type": "long"
}, ..}
any help please?
Kibana index pattern :
PS: The JSON code of the mapping is not completed due to the post rules.
Simply, the error message indicates that there is nothing shown regarding your aggregation, metric, time range etc. Therefore, even though documents exist on elasticsearch, they cannot be drawn on a visualisation. In order to solve the issue:
select the aggregation method considering field data type
set a suitable metric along with the right time range which returns some result
[Solution]
I found a solution for that, in fact httpbeat 5.6.x cannot work with kibana , only httpbeat v4.1.0 is supported ! so to visualize data you have to change the version of httpbeat (the other version give nested json documents and the nested fields are not supported with kibana )
I have indexed my pdf file in elastic search using ingest-attachment processor plugin and now am search my file based on the contents available in PDF.
For Example, am having some contents like this in my pdf.
Hello I m Karthikeyan. My mail id Karthikeyan#gmail.com, My mob no 4573894833.
While am searching using Java API, am able to search like the following.
Search For,
Karthikeyan#gmail.com am able to get the file.
But,
If i search for,
#gm means am not able to get the file, am expecting that i should get the file because, this file have my search keyword #gm.
How can i do this. ?
Am using tokenizer with min_gram & max_gram as 3 each.
Please find the below java api that i have used, but none of them giving me the results as expected.
QueryStringQueryBuilder attachmentQB = new QueryStringQueryBuilder("#gm");
Please find my below mappings details.
PUT attach_local
{
"settings": {
"analysis": {
"analyzer": {
"custom_analyzer": {
"type": "custom",
"tokenizer": "my_tokenizer",
"char_filter": [
"html_strip"
],
"filter": [
"lowercase",
"asciifolding"
]
}
},
"tokenizer": {
"my_tokenizer": {
"type": "ngram",
"min_gram": 3,
"max_gram": 3,
"token_chars": [
"letter",
"digit"
]
}
}
}
},
"mappings": {
"doc": {
"properties": {
"attachment": {
"properties": {
"content": {
"type": "text",
"analyzer": "custom_analyzer"
},
"content_length": {
"type": "long"
},
"content_type": {
"type": "text"
},
"language": {
"type": "text"
}
}
},
"resume": {
"type": "text"
}
}
}
}
}
You can see how ES tokenizes your search text using
POST /attach_local/_analyze
{
"analyzer": "custom_analyzer",
"text": "#gm"
}
That will tell you if the # character is dropped or not. If it is then that would explain the behavior since your inverted index has all trigrams and you are searching for a bigram.
I am very new to Talend Open Studio for DI. I am trying to read data from the below JSON File :
{
"data": [
{
"id": "X999_Y999",
"from": {
"name": "Tom Brady", "id": "X12"
},
"message": "Looking forward to 2010!",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/X999/posts/Y999"
},
{
"name": "Like",
"link": "http://www.facebook.com/X999/posts/Y999"
}
],
"type": "status",
"created_time": "2010-08-02T21:27:44+0000",
"updated_time": "2010-08-02T21:27:44+0000"
},
{
"id": "X998_Y998",
"from": {
"name": "Peyton Manning", "id": "X18"
},
"message": "Where's my contract?",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/X998/posts/Y998"
},
{
"name": "Like",
"link": "http://www.facebook.com/X998/posts/Y998"
}
],
"type": "status",
"created_time": "2010-08-02T21:27:44+0000",
"updated_time": "2010-08-02T21:27:44+0000"
}
]
}
I want to load three attributes into my table ( id, actions_name and actions_link). So, in the first step (tFileInputJSON) - I tried to do a Loop Json query as below:
Here, am able to extract the rows as I needed. But, then I used a tExtractJSONField to extract individual fields under "actions" for each "id" using XPath expressions as below:
I tried several other ways to extract the fields but could not do this. Also, not able to find any correct post in stack overflow and talent forums very relevant to my question. Could somebody please help?
Arrange the job like ,
tFileInputJSON is like,
tExtractJSONFields is like,
Then you will get output as,