{"__v":0,"_id":"55fc9b7b3c21291900e7e0ea","category":{"__v":1,"_id":"55fc9b7a3c21291900e7e0de","pages":["55fc9b7b3c21291900e7e0e8","55fc9b7b3c21291900e7e0e9","55fc9b7b3c21291900e7e0ea","55fc9b7b3c21291900e7e0eb","55fc9b7b3c21291900e7e0ec"],"project":"5553d36165e8260d0024419a","version":"55fc9b793c21291900e7e0d7","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-14T20:15:44.034Z","from_sync":false,"order":6,"slug":"conditions","title":"Conditions"},"parentDoc":null,"project":"5553d36165e8260d0024419a","user":"5553d33065e8260d00244199","version":{"__v":12,"_id":"55fc9b793c21291900e7e0d7","project":"5553d36165e8260d0024419a","createdAt":"2015-09-18T23:17:13.545Z","releaseDate":"2015-09-18T23:17:13.545Z","categories":["55fc9b7a3c21291900e7e0d8","55fc9b7a3c21291900e7e0d9","55fc9b7a3c21291900e7e0da","55fc9b7a3c21291900e7e0db","55fc9b7a3c21291900e7e0dc","55fc9b7a3c21291900e7e0dd","55fc9b7a3c21291900e7e0de","55fc9b7a3c21291900e7e0df","55fc9b7a3c21291900e7e0e0","55fc9b7a3c21291900e7e0e1","55fc9b7a3c21291900e7e0e2","55fc9b7a3c21291900e7e0e3","55fc9bad4c80910d00b9bece","56394a0c3539050d00082122","56394a2f68b11f0d0048c9ff","56394a462fc5520d001a4db3","56394a4c2fc5520d001a4db4","56394a5b049e420d00476b5c","56394a6a2fc5520d001a4db5","56394f791593e4190073a44b","567b3adfb56bac0d0019d8d9","569d590e5a2b060d008741eb","569ea93dffccd10d00a05c7f"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-15T20:36:08.062Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"APImetrics can handle the JSON content returned by a specific API Call. We also [support XML](https://apimetrics.readme.io/docs/parsing-xml-content). This allows you to:\n\n- Set variables in a Work Flow\n- Set Custom Events based on expect strings\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Handling Content\"\n}\n[/block]\nIf the API you’re testing returns JSON formatted data, you may also check for a specific value inside that JSON.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Format\",\n  \"body\": \"use a dot (.) to access attributes of a JSON object, alternatively subscript syntax ([]) can be used. The following lines do the same:\\nfoo.bar\\nfoo['bar']\"\n}\n[/block]\n\nThis means if the response is a list, you can actually access the first item by either:\nmy_list[0]\nmy_list.0\n\nFor example, if the response JSON looked like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \" {\\n    \\\"outboundSMSResponse\\\": {\\n        \\\"resourceReference\\\": {\\n            \\\"resourceURL\\\": \\\"https://api.foo.com/3/smsmessaging/outbound/requests/44628950/SMSa9b5cf0f4a944c16/deliveryInfos\\\"\\n        }, \\n        \\\"messageId\\\": \\\"SMSa9b5cf0f4a944c16\\\"\\n    }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\nand you wanted to check the value of the resourceURL. you would enter:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"outboundSMSResponse.resourceReference.resourceURL\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nor\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"outboundSMSResponse['resourceReference']['resourceURL']\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\nOr, if the response JSON looked like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"Recognition\\\": {\\n        \\\"Info\\\": { \\\"metrics\\\": { \\\"audioTime\\\": 7.94000006, \\\"audioBytes\\\": 127092 } }, \\n        \\\"Status\\\": \\\"OK\\\", \\n        \\\"ResponseId\\\": \\\"f160c005a1b78d2abda5eda4aa935a6f\\\", \\n        \\\"NBest\\\": [\\n            {\\n                \\\"Confidence\\\": 0.39000000000000001, \\n                \\\"ResultText\\\": \\\"Hello this is a test. What time is it goodbye.\\\", \\n                \\\"LanguageId\\\": \\\"en-US\\\", \\n                \\\"Grade\\\": \\\"accept\\\", \\n                \\\"Hypothesis\\\": \\\"hello this is a test what time is it goodbye\\\", \\n                \\\"Words\\\": [\\n                    \\\"Hello\\\", \\n                    \\\"this\\\", \\n                    \\\"is\\\", \\n                    \\\"a\\\", \\n                    \\\"test.\\\", \\n                    \\\"What\\\", \\n                    \\\"time\\\", \\n                    \\\"is\\\", \\n                    \\\"it\\\", \\n                    \\\"goodbye.\\\"\\n                ]\\n            }\\n        ]\\n    }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n \nand you wanted to check that the sixth word returned in the words structure was “What”, you would enter:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Recognition.NBest.0.Words.5\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nor\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Recognition.NBest[0].Words[5]\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"parsing-returned-content","type":"basic","title":"Parsing JSON Content"}

Parsing JSON Content


APImetrics can handle the JSON content returned by a specific API Call. We also [support XML](https://apimetrics.readme.io/docs/parsing-xml-content). This allows you to: - Set variables in a Work Flow - Set Custom Events based on expect strings [block:api-header] { "type": "basic", "title": "Handling Content" } [/block] If the API you’re testing returns JSON formatted data, you may also check for a specific value inside that JSON. [block:callout] { "type": "info", "title": "Format", "body": "use a dot (.) to access attributes of a JSON object, alternatively subscript syntax ([]) can be used. The following lines do the same:\nfoo.bar\nfoo['bar']" } [/block] This means if the response is a list, you can actually access the first item by either: my_list[0] my_list.0 For example, if the response JSON looked like this: [block:code] { "codes": [ { "code": " {\n \"outboundSMSResponse\": {\n \"resourceReference\": {\n \"resourceURL\": \"https://api.foo.com/3/smsmessaging/outbound/requests/44628950/SMSa9b5cf0f4a944c16/deliveryInfos\"\n }, \n \"messageId\": \"SMSa9b5cf0f4a944c16\"\n }\n}", "language": "json" } ] } [/block] and you wanted to check the value of the resourceURL. you would enter: [block:code] { "codes": [ { "code": "outboundSMSResponse.resourceReference.resourceURL", "language": "text" } ] } [/block] or [block:code] { "codes": [ { "code": "outboundSMSResponse['resourceReference']['resourceURL']", "language": "text" } ] } [/block] Or, if the response JSON looked like this: [block:code] { "codes": [ { "code": "{\n \"Recognition\": {\n \"Info\": { \"metrics\": { \"audioTime\": 7.94000006, \"audioBytes\": 127092 } }, \n \"Status\": \"OK\", \n \"ResponseId\": \"f160c005a1b78d2abda5eda4aa935a6f\", \n \"NBest\": [\n {\n \"Confidence\": 0.39000000000000001, \n \"ResultText\": \"Hello this is a test. What time is it goodbye.\", \n \"LanguageId\": \"en-US\", \n \"Grade\": \"accept\", \n \"Hypothesis\": \"hello this is a test what time is it goodbye\", \n \"Words\": [\n \"Hello\", \n \"this\", \n \"is\", \n \"a\", \n \"test.\", \n \"What\", \n \"time\", \n \"is\", \n \"it\", \n \"goodbye.\"\n ]\n }\n ]\n }\n}", "language": "json" } ] } [/block] and you wanted to check that the sixth word returned in the words structure was “What”, you would enter: [block:code] { "codes": [ { "code": "Recognition.NBest.0.Words.5", "language": "text" } ] } [/block] or [block:code] { "codes": [ { "code": "Recognition.NBest[0].Words[5]", "language": "text" } ] } [/block]