Storing Json response element in a variable using Karate - rest
Storing the following json response in a variable
[{"Resort":"SANRS","ResvNameID":14396162,"ConfirmationNo":"86749976"},
{"Resort":"SANRS","ResvNameID":13123123,"ConfirmationNo":"98932423"}]
And def allres = response
And print allres.reservations[0].ResvNameID does not print anything? What's wrong here?
Your JSON path is wrong.
Try:
* print allres[0].ResvNameID
Output:
[print] 14396162
Related
Converting a string that represents a list into an actual list in Jython?
I have a string in Jython that represents a list of JSON arrays: [{"datetime": 1570216445000, "type": "test"},{"datetime": 1570216455000, "type": "test2"}] If I try to iterate over this though, it just iterates over each character. How can I make it iterate over the actual list so I can get each JSON array out? Background info - This script is being run in Apache NiFi, below is the code that the string originates from: from org.apache.commons.io import IOUtils ... def process(self, inputStream): text = IOUtils.toString(inputStream,StandardCharsets.UTF_8)
You can parse a JSON similar to how you do it in Python. Sample Code: import json # Sample JSON text text = '[{"datetime": 1570216445000, "type": "test"},{"datetime": 1570216455000, "type": "test2"}]' # Parse the JSON text obj = json.loads(text) # 'obj' is a dictionary print obj[0]['type'] print obj[1]['type'] Output: > jython json_string_to_object.py test test2
Gatling: check binary response not empty
I'm doing some tests with Gatling using Scala. I'm trying to check whether a response body that is returned is not empty. I'm doing it like this: def getImages: ChainBuilder = feed(credentials) .exec(http("Get Image") .get(GET_MY_URI) .queryParam("guid", "${branch}") .queryParam("t", "0.458654") .check(status.is(200)) .check(bodyString.transform(_.size > 1).is(true))) But it's not working. I get: java.nio.charset.MalformedInputException: Input length = 1 Does somebody know how to achieve what I'm trying?
Replace .check(bodyString.transform(_.size > 1).is(true))) with .check(bodyBytes.exists) All the DSL is explained here: https://gatling.io/docs/current/cheat-sheet/
How to parse json object in UnityScript?
I am following this link http://wiki.unity3d.com/index.php/JSONUtils but not able to parse json object. What I have tried so far: function SerializeObject() { var object = {"response":[{"id":"100","name":"Guest","score":"14","game":"3,6,9,7,1,8,2,4","date":"2015-02-28 11:22:32"},{"id":"99","name":"Guest","score":"18","game":"7,8,2,5,6,9,4,3","date":"2015-02-28 11:19:35"},{"id":"89","name":"Guest","score":"17","game":"5,7,2,8,6,1,3,9","date":"2015-02-26 16:39:59"},{"id":"96","name":"Guest","score":"18","game":"2,6,1,5,9,7,8,4","date":"2015-02-26 16:34:05"},{"id":"97","name":"Guest","score":"16","game":"1,7,3,4,8,2,6,5","date":"2015-02-26 16:32:30"},{"id":"95","name":"Guest","score":"14","game":"1,3,7,4,6,9,2,8","date":"2015-02-23 19:20:07"},{"id":"90","name":"Guest","score":"16","game":"8,3,9,6,4,5,2,7","date":"2015-02-23 16:48:55"},{"id":"92","name":"Guest","score":"17","game":"5,2,1,9,7,4,3,8","date":"2015-02-23 16:48:28"},{"id":"91","name":"Guest","score":"16","game":"2,1,3,9,6,7,8,4","date":"2015-02-23 16:48:06"},{"id":"94","name":"Guest","score":"14","game":"5,2,8,7,6,1,9,4","date":"2015-02-23 16:47:25"},{"id":"93","name":"Guest","score":"16","game":"8,9,2,7,4,6,3,1","date":"2015-02-23 16:45:44"},{"id":"88","name":"jacky chain","score":"15","game":"1,2,5,4,7,9,3,6","date":"2015-02-23 13:35:20"},{"id":"87","name":"Genie","score":"15","game":"8,9,5,7,1,4,2,3","date":"2015-02-22 16:19:32"},{"id":"86","name":"Genie","score":"15","game":"9,7,3,2,1,5,8,4","date":"2015-02-22 16:16:13"},{"id":"85","name":"Genie","score":"15","game":"7,1,4,6,5,3,9,8","date":"2015-02-22 14:25:39"},{"id":"83","name":"new","score":"18","game":"2,5,4,1,8,9,7,6","date":"2015-02-22 11:11:49"},{"id":"84","name":"Guest","score":"15","game":"9,8,3,5,1,4,2,7","date":"2015-02-22 09:48:28"},{"id":"80","name":"Guest","score":"16","game":"5,4,2,3,1,8,7,6","date":"2015-02-22 08:24:55"},{"id":"82","name":"Guestr","score":"15","game":"8,1,9,5,7,4,6,3","date":"2015-02-21 21:00:37"},{"id":"81","name":"Guest","score":"18","game":"9,4,2,7,6,5,1,8","date":"2015-02-21 20:54:51"},{"id":"79","name":"Guest","score":"15","game":"2,6,9,5,8,3,1,7","date":"2015-02-21 20:37:30"},{"id":"78","name":"Guest","score":"15","game":"3,6,9,7,1,5,4,2","date":"2015-02-21 20:35:27"},{"id":"77","name":"Guest","score":"17","game":"5,3,7,9,8,4,1,6","date":"2015-02-21 16:04:17"},{"id":"64","name":"Guest","score":"17","game":"7,9,8,4,6,1,3,5","date":"2015-02-21 16:03:41"},{"id":"76","name":"new","score":"18","game":"9,3,4,8,6,5,2,1","date":"2015-02-21 15:27:25"}]}; for( var test in object.Keys ) { Debug.Log( "Object["+test+"] : "+object[test] ); } } I see the below line in the Log: Object[response] : Boo.Lang.Hash[] Now i want to extract value from this object. I would appreciate your help on this, thank you.
Your log message is telling you that object["response"] is returning an array of hashes as you would expect from the JSON you parsed. Now you need to iterate over that array which will give you each internal hash object, the first one being: {"id":"100","name":"Guest","score":"14","game":"3,6,9,7,1,8,2,4","date":"2015-02-28 11:22:32"}
How to get result in json from overpass-turbo?
Is it possible to get result in JSON from http://overpass-turbo.eu/ (or directly from openstreetmap) ? My request is: ( way (around:2000,55.693309807744484,21.151986122131348) [highway~"^(primary|secondary|tertiary|residential)$"] [name]; >;);out;
You need to add this line in front of your statement: [out:json]; ...
This is the query: http://overpass-api.de/api/interpreter?data=[out:json]%20;%20(%20way%20(around:2000,55.693309807744484,21.151986122131348)%20[highway~%22^(primary|secondary|tertiary|residential)$%22]%20[name];%20%3E;);%20out; Yours was missing: [out:json] ; <your part> and %20 before out;
ZEND: Return HTML as string using Render?
I have: $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $this->render("voucher-list"); The problem is, when I execute: $this->render("voucher-list"); It actually prints the information to screen. I want to return the data as an HTML string. This DOES NOT work: $htmlcontent = $this->render("voucher-list"); How would I go about returning this information as a string?
If you want to send the data into JSON format then you need to make the array of data and use the following code to send the data: $data = array(3,4,'test', 'my-name' => 3,4); //suppose this is your data $this->_helper->viewRenderer->setNoRender(true); $this->view->layout()->disableLayout(); echo Zend_Json::encode($data); And you will get the data in JSON format. See this: Zend Framework JSON Output