This is the example JSON
{
"customerId": 0,
"authorizedCustomerIds": [
0
],
"creativeVersionId": 0,
"description": "string",
"version": "string",
"duration": 0,
"frameRate": 0,
"previewImage": "string",
"previewVideo": "string",
"renderScript": "string",
"renderScriptType": "string",
"elements": [
{
"id": 0,
"type": "IMAGE",
"name": "string1",
"parentId": 0,
"presetId": 0,
"properties": [
{
"name": "string",
"value": {},
"type": "ALPHABETIC",
"producesVideo": true,
"renderScriptId": "string"
}
]
},
{
"id": 1,
"type": "TEXT",
"name": "string2",
"parentId": 0,
"presetId": 0,
"properties": [
{
"name": "string",
"value": {},
"type": "ALPHABETIC",
"producesVideo": false,
"renderScriptId": "string"
}
]
}
],
"globalElements": [
{
"id": 0,
"disabled": true
}
],
"shots": [
{
"name": "string",
"displayOrder": 0,
"startFrame": 0,
"duration": 0,
"thumbnailFrame": 0,
"elements": [
{
"id": 0,
"disabled": true
}
]
}
],
"sizes": [
{
"name": "string",
"displayOrder": 0,
"main": true,
"width": 0,
"height": 0,
"properties": [
{
"templateElementId": 0,
"propertyName": "string",
"linked": true,
"value": {}
}
]
}
]
}
I need to get the element name which type is TEXT and the properties "producesVideo" is false.
I tried this way but it not works
$..elements[?(#.type == 'TEXT' && #.properties[?(#.producesVideo == false)])].name
Then I need to extract the path with rest assured
.extract().path();
using find or findAll conditions
What JSONPath implementation are you using? For that document and JSONPath expression, some implementations, e.g. jayway Java and jsoncons C++, will return the value result
[
"string2"
]
or the path result
[
"$['elements'][1]['name']"
]
Other implementations, e.g. Goessner Javascript, can't digest a filter expression with a subfilter. Christoph Burgmer's JSONPath Comparison covers that case here.
using rest assured find and findAll expressions the jsonpath should be like this:
.extract().path("elements.findAll{it.type == 'TEXT' && it.properties.find{it.producesVideo == false}}.name");
Related
Probably there are many question on JSON schema, however, I couldn't find an answer I was looking for.
I have a JSON message where the block inside FlagDetails array can come a max of 300 times. How do I restrict this using the schema which I have created below so that Time and UID can come max of 300 but max occurrences is 1 per array block.
JSON body:
{
"SData": {
"IData": {
"IDatas": {
"Flag": "Yes",
"FlagDetails": [
{
"Time": "2012-07-06 09:30:00",
"UID": 1234567
},
{
"Time": "2012-07-06 09:30:00",
"UID": 1234567
}
]
}
}
}
}
JSON schema:
{
"definitions": {},
"type": "object",
"required": [
"SData"
],
"properties": {
"SData": {
"title": "SData",
"type": "object",
"required": [
"IData"
],
"properties": {
"IData": {
"title": "IData",
"type": "object",
"required": [
"IDatas"
],
"properties": {
"IDatas": {
"title": "IDatas",
"type": "object",
"required": [
"Flag"
],
"properties": {
"Flag": {
"title": "Flag",
"type": "string",
"default": "",
"examples": [
"Yes"
],
"minLength": 2,
"maxLength": 3,
"minOccurs": 0,
"maxOccurs": 1,
"pattern": "^.*$"
},
"FlagDetails": {
"title": "FlagDetails",
"type": "array",
"default": [],
"items": {
"title": "Items",
"type": "object",
"properties": {
"Time": {
"title": "Time",
"type": "string",
"default": "",
"examples": [
"2012-07-06 09:30:00"
],
"minOccurs": 0,
"pattern": "^.*$"
},
"UID": {
"title": "UId",
"type": "integer",
"default": "",
"examples": [
"12345678912"
],
"minLength": 4,
"maxLength": 12,
"minOccurs": 0,
"pattern": "^.*$"
}
}
}
}
}
}
}
}
}
}
}
}
The answer to this is "minItems" & "maxItems". I have used those and it works perfectly.
"FlagDetails": {
"title": "FlagDetails",
"type": "array",
**"minItems": 0,
"maxItems": 300,**
"default": []
We created a Cloudformation template for auto implementation of the AWS Sitewise monitoring dashboard. We would like to dynamically refer and assign the Asset logical id inside the below dashboard definition.
{\"widgets\":[{\"type\":\"sc-line-chart\",\"title\":\"power_all_plants_5m\",\"x\":0,\"y\":0,\"height\":3,\"width\":3,\"metrics\":[{\"type\":\"iotsitewise\",\"label\":\"power_all_plants_5m (All Power Plants)\",\"assetId\":\"0cd25cb9-89f9-4a93-b2bf-88050436f700\",\"propertyId\":\"fd34bba7-4ea2-4d62-9058-ab78b726b61a\",\"dataType\":\"DOUBLE\"}],\"alarms\":[],\"properties\":{\"colorDataAcrossThresholds\":true},\"annotations\":{\"y\":[]}},{\"type\":\"sc-line-chart\",\"title\":\"Generator-1\",\"x\":3,\"y\":0,\"height\":3,\"width\":3,\"metrics\":[{\"type\":\"iotsitewise\",\"label\":\"sum_watts_5m (Generator-1)\",\"assetId\":\"45b97aaa-3f0c-4312-a8a5-a00e4da8ec37\",\"propertyId\":\"e22d9a23-4ac8-432a-816b-cc4a2138b287\",\"dataType\":\"DOUBLE\"},{\"type\":\"iotsitewise\",\"label\":\"rpm (Generator-1)\",\"assetId\":\"45b97aaa-3f0c-4312-a8a5-a00e4da8ec37\",\"propertyId\":\"c6a40902-f07b-40ba-b6c5-3509b069dd4c\",\"dataType\":\"DOUBLE\"}],\"alarms\":[],\"properties\":{\"colorDataAcrossThresholds\":true},\"annotations\":{\"y\":[]}},{\"type\":\"sc-line-chart\",\"title\":\"Generator-2\",\"x\":0,\"y\":3,\"height\":3,\"width\":3,\"metrics\":[{\"type\":\"iotsitewise\",\"label\":\"sum_watts_5m (Generator-2)\",\"assetId\":\"b999319c-20ec-4060-b3b7-bc5ce7ef189c\",\"propertyId\":\"e22d9a23-4ac8-432a-816b-cc4a2138b287\",\"dataType\":\"DOUBLE\"},{\"type\":\"iotsitewise\",\"label\":\"rpm (Generator-2)\",\"assetId\":\"b999319c-20ec-4060-b3b7-bc5ce7ef189c\",\"propertyId\":\"c6a40902-f07b-40ba-b6c5-3509b069dd4c\",\"dataType\":\"DOUBLE\"}],\"alarms\":[],\"properties\":{\"colorDataAcrossThresholds\":true},\"annotations\":{\"y\":[]}}]}
This JSON literal is converted to YAML by adding backward slashes () along with the double quotes because we are using YAML as the default language of the Cloudformation template otherwise it looks like the below.
{
"widgets": [
{
"type": "sc-line-chart",
"title": "power_all_plants_5m",
"x": 0,
"y": 0,
"height": 3,
"width": 3,
"metrics": [
{
"type": "iotsitewise",
"label": "power_all_plants_5m (All Power Plants)",
"assetId": "0cd25cb9-89f9-4a93-b2bf-88050436f700",
"propertyId": "fd34bba7-4ea2-4d62-9058-ab78b726b61a",
"dataType": "DOUBLE"
}
],
"alarms": [],
"properties": {
"colorDataAcrossThresholds": true
},
"annotations": {
"y": []
}
},
{
"type": "sc-line-chart",
"title": "Generator-1",
"x": 3,
"y": 0,
"height": 3,
"width": 3,
"metrics": [
{
"type": "iotsitewise",
"label": "sum_watts_5m (Generator-1)",
"assetId": "45b97aaa-3f0c-4312-a8a5-a00e4da8ec37",
"propertyId": "e22d9a23-4ac8-432a-816b-cc4a2138b287",
"dataType": "DOUBLE"
},
{
"type": "iotsitewise",
"label": "rpm (Generator-1)",
"assetId": "45b97aaa-3f0c-4312-a8a5-a00e4da8ec37",
"propertyId": "c6a40902-f07b-40ba-b6c5-3509b069dd4c",
"dataType": "DOUBLE"
}
],
"alarms": [],
"properties": {
"colorDataAcrossThresholds": true
},
"annotations": {
"y": []
}
},
{
"type": "sc-line-chart",
"title": "Generator-2",
"x": 0,
"y": 3,
"height": 3,
"width": 3,
"metrics": [
{
"type": "iotsitewise",
"label": "sum_watts_5m (Generator-2)",
"assetId": "b999319c-20ec-4060-b3b7-bc5ce7ef189c",
"propertyId": "e22d9a23-4ac8-432a-816b-cc4a2138b287",
"dataType": "DOUBLE"
},
{
"type": "iotsitewise",
"label": "rpm (Generator-2)",
"assetId": "b999319c-20ec-4060-b3b7-bc5ce7ef189c",
"propertyId": "c6a40902-f07b-40ba-b6c5-3509b069dd4c",
"dataType": "DOUBLE"
}
],
"alarms": [],
"properties": {
"colorDataAcrossThresholds": true
},
"annotations": {
"y": []
}
}
]
}
We would like to assign Asset ID dynamically using "!Ref" with pre-created Asset. We have tried the below variations but no fate.
Existing value -> 0cd25cb9-89f9-4a93-b2bf-88050436f700
Tried below changes:-
[{\"Ref\":\"GeneratorAsset\"}]
!Ref GeneratorAsset
\"!Ref GeneratorAsset\"
{\"Ref\":GeneratorAsset}
{\"Ref\":\"GeneratorAsset\"}
\"{\"Ref\":\"GeneratorAsset\"}\"
\"{\"Fn::Sub\":${GeneratorAsset}}\"
\"{\"Fn::Sub\":${!GeneratorAsset}}\"
\"{\"Fn::Sub\":${!GeneratorAsset} }\"
Here GeneratorAsset is a resource that is already created before Dashboard. Request any Cloudformation expert to help us replace the id value with the correct dynamic string.
Ref link:- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iotsitewise-dashboard.html
I have this Json ( is a test database, no data is true here )
{
"pguid": "4EA979A2-E578-4DA3-89DB-24082F3092AA",
"lastEnrollTguid": "EA98B161-04D3-4F0A-920A-58DBFF3C2274",
"timestamp": 1016086888000,
"keys": [
{
"id": "gr",
"value": "1907971"
}
],
"biographics": [
{
"id": "localNascimento",
"value": "JOINVILLE SC"
},
{
"id": "dataNascimento",
"value": "1859-03-08"
},
{
"id": "mae",
"value": "ANTA MARCIA PINHEAD"
},
{
"id": "nome",
"value": "MIR PINHEAD"
}
],
"biometric": [
{
"source": "ORIGINAL",
"type": "FACE",
"format": "JPEG",
"properties": {
"width": 0,
"height": 0,
"resolution": 500,
"ratio": 0,
"matcherId": 0,
"extractorId": 0
},
"index": 10,
"content": "5215421547"
}
],
"labels": [
"SC",
"CIVIL",
"MASCULINO",
"JOINVILLE"
],
"history": {
"events": [
{
"type": "ENROLL",
"tguid": "3C1B0D1F-9143-4C24-A351-E88A19317AC9",
"timestamp": 1014086658288
},
{
"type": "UPDATE",
"tguid": "EA98B161-04D3-4F0A-920A-58DBFF3C2274",
"timestamp": 1016786888028
}
]
}
}
I want to retrive only de tguid in history array, and if exist a way to do this, use de index of the array to acomplish that.
Here I tryed to acomplish that ( and miserable failed in that )
example ( and it do not work ):
jq '.[].history.events.tguid[1]' /tmp/teste.json
I want to retrieve the pguid in a index to work with that.
Someone have any ideas?
try this
jq '.history.events | .[1].tguid' /tmp/teste.json
tnks everyone
jq '.[].history.events | .[0].tguid' /tmp/teste1.json
I have below JSON and i require to validate the status based on given id in my automation script. For that JSON path require
[
[
{
"id": 9905130204,
"category": {
"id": 0,
"name": "string"
},
"name": "doggie",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
},
{
"id": 9905130203,
"name": "Jeffs Doggie11/6/2019 2:44:53 PM",
"photoUrls": [
"string"
],
"tags": [],
"status": "available"
},
{
"id": 9905130217,
"name": "Goot Doggie",
"photoUrls": [
"https://media.karousell.com/media/photos/products/2017/09/14/doggi_door_stopper_1505372529_5cdd1eba0"
],
"tags": [],
"status": "available"
}
]
]
I want to extract "status": "available" based on "id": 9905130217. No clue how to do that, please help.
You can use the following jsonpath expression to find the status where id = n:
$.[?(#.id == 'n')].status
So, for your specific case:
$.[?(#.id == '9905130217')].status
Note, that this assumes id is unique.
I am trying to use Postman to make a POST request to the Magento API and I am getting back an error message that says:
{"message":"Unable to save product"}.
Here is the code I am running through Postman.
{
"product":{"sku": "123456","name": "New Shoe","attribute_set_id": 11,"price": "status": "visibility": "type_id": ""created_at": "2016-12-04 15:03:"updated_at": "2016-12-04 15:03:"}
I am running it through a POST request under the /V1/products/ directory. I am able to Get information from the API with the access key I am using so I do not believe that it is an Authorization issue.
I have tried doing the same request changing some of the information using PUT and I am getting the same result. Any suggestions or thoughts would be greatly appreciated!
You can open Magento2 source code, try to find this file vendor/magento/module-catalog/Model/ProductRepository.php:732
Change last catch to this:
catch (\Exception $e) {
echo $e->getMessage();
die();
throw new CouldNotSaveException(__('Unable to save product'), $e);
}
You will see what your problem is. Example:
show exception message
catalogProductRepositoryV1
POST /V1/products
Create product
Body > Data
{
"product": {
"id": 0,
"sku": "string",
"name": "string",
"attributeSetId": 0,
"price": 0,
"status": 0,
"visibility": 0,
"typeId": "string",
"createdAt": "string",
"updatedAt": "string",
"weight": 0,
"extensionAttributes": {
"downloadableProductLinks": [
{
"id": 0,
"title": "string",
"sortOrder": 0,
"isShareable": 0,
"price": 0,
"numberOfDownloads": 0,
"linkType": "string",
"linkFile": "string",
"linkFileContent": {
"fileData": "string",
"name": "string",
"extensionAttributes": {}
},
"linkUrl": "string",
"sampleType": "string",
"sampleFile": "string",
"sampleFileContent": {
"fileData": "string",
"name": "string",
"extensionAttributes": {}
},
"sampleUrl": "string",
"extensionAttributes": {}
}
],
"downloadableProductSamples": [
{
"id": 0,
"title": "string",
"sortOrder": 0,
"sampleType": "string",
"sampleFile": "string",
"sampleFileContent": {
"fileData": "string",
"name": "string",
"extensionAttributes": {}
},
"sampleUrl": "string",
"extensionAttributes": {}
}
],
"stockItem": {
"itemId": 0,
"productId": 0,
"stockId": 0,
"qty": 0,
"isInStock": true,
"isQtyDecimal": true,
"showDefaultNotificationMessage": true,
"useConfigMinQty": true,
"minQty": 0,
"useConfigMinSaleQty": 0,
"minSaleQty": 0,
"useConfigMaxSaleQty": true,
"maxSaleQty": 0,
"useConfigBackorders": true,
"backorders": 0,
"useConfigNotifyStockQty": true,
"notifyStockQty": 0,
"useConfigQtyIncrements": true,
"qtyIncrements": 0,
"useConfigEnableQtyInc": true,
"enableQtyIncrements": true,
"useConfigManageStock": true,
"manageStock": true,
"lowStockDate": "string",
"isDecimalDivided": true,
"stockStatusChangedAuto": 0,
"extensionAttributes": {}
},
"giftcardAmounts": [
{
"websiteId": 0,
"value": 0,
"websiteValue": 0,
"extensionAttributes": {}
}
],
"configurableProductOptions": [
{
"id": 0,
"attributeId": "string",
"label": "string",
"position": 0,
"isUseDefault": true,
"values": [
{
"valueIndex": 0,
"extensionAttributes": {}
}
],
"extensionAttributes": {},
"productId": 0
}
],
"configurableProductLinks": [
0
],
"bundleProductOptions": [
{
"optionId": 0,
"title": "string",
"required": true,
"type": "string",
"position": 0,
"sku": "string",
"productLinks": [
{
"id": "string",
"sku": "string",
"optionId": 0,
"qty": 0,
"position": 0,
"isDefault": true,
"price": 0,
"priceType": 0,
"canChangeQuantity": 0,
"extensionAttributes": {}
}
],
"extensionAttributes": {}
}
]
},
"productLinks": [
{
"sku": "string",
"linkType": "string",
"linkedProductSku": "string",
"linkedProductType": "string",
"position": 0,
"extensionAttributes": {
"qty": 0
}
}
],
"options": [
{
"productSku": "string",
"optionId": 0,
"title": "string",
"type": "string",
"sortOrder": 0,
"isRequire": true,
"price": 0,
"priceType": "string",
"sku": "string",
"fileExtension": "string",
"maxCharacters": 0,
"imageSizeX": 0,
"imageSizeY": 0,
"values": [
{
"title": "string",
"sortOrder": 0,
"price": 0,
"priceType": "string",
"sku": "string",
"optionTypeId": 0
}
],
"extensionAttributes": {}
}
],
"mediaGalleryEntries": [
{
"id": 0,
"mediaType": "string",
"label": "string",
"position": 0,
"disabled": true,
"types": [
"string"
],
"file": "string",
"content": {
"base64EncodedData": "string",
"type": "string",
"name": "string"
},
"extensionAttributes": {
"videoContent": {
"mediaType": "string",
"videoProvider": "string",
"videoUrl": "string",
"videoTitle": "string",
"videoDescription": "string",
"videoMetadata": "string"
}
}
}
],
"tierPrices": [
{
"customerGroupId": 0,
"qty": 0,
"value": 0,
"extensionAttributes": {}
}
],
"customAttributes": [
{
"attributeCode": "string",
"value": "string"
}
]
},
"saveOptions": true
}