http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=test&sl=en&tl=en&restrict=pr%2Cde&client=te
(replace test with your favorite keyword)
using this i want to write simple dictionary....
problem - api give json output how i get it using java?
Simple Parsing
Per default, JSON will just produce a nested graph of maps and lists. Here is an example of default parsing:
import org.svenson.JSONParser;
// assume json to be a JSON datasets as String
Object o = JSONParser.defaultJSONParser().parse(json);
o will now contain either a map or a list instance, depending on whether the first symbol in the JSON is '{' or '['.
Related
I need to loop a string (split by ',') and get each element passed to the feature files automatically. I know there is excellent support for json array data-driven test, but does it support data-driven with normal strings or string array
As I know, I need to get it converted to a json array to support data-driven test at runtime, however, I want to know any existing support for normal array looping directly and automatically.
Here is my string(separated by ',') that needs to get passed as request parameter:
"PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT"
Because my string is dynamically produced at runtime, I want to loop it automatically and pass to other feature files, not manually,
Note that converting arrays into other "shapes" is easy in Karate. And in 0.9.3 we introduced the karate.mapWithKey() API, so you can do this:
* def string = 'PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT'
* def array = string.split(',')
* def list = karate.mapWithKey(array, 'name')
* print list
So you can see, list is ready to use for data-driven features. Also note that you can use this in dynamic scenario outlines !
I need to loop a string (split by ',') and get each element passed to the feature files automatically. I know there is excellent support for json array data-driven test, but does it support data-driven with normal strings or string array
As I know, I need to get it converted to a json array to support data-driven test at runtime, however, I want to know any existing support for normal array looping directly and automatically.
Here is my string(separated by ',') that needs to get passed as request parameter:
"PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT"
Because my string is dynamically produced at runtime, I want to loop it automatically and pass to other feature files, not manually,
Note that converting arrays into other "shapes" is easy in Karate. And in 0.9.3 we introduced the karate.mapWithKey() API, so you can do this:
* def string = 'PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT'
* def array = string.split(',')
* def list = karate.mapWithKey(array, 'name')
* print list
So you can see, list is ready to use for data-driven features. Also note that you can use this in dynamic scenario outlines !
What is the difference between reading the properties from payload. for example there is a property in the payload which is named as con_id. when i read this property like this #[payload.con_id] then it is coming as null. where as #[payload.'con_id'] is returning the value.
few other notations which i know of is #[payload['con_id']] or #[json:con_id]
which one should be used at which scenario? if there are any special cases to use any specific notation then please let me know the scenario also.
Also, what is the common notation that has to be used from a mule soft platform supported point of view.
In Mule 3 any of those syntax are valid. Except the json: evaluator is for querying json documents where as the others are for querying maps/objects. Also the json: evaluator is deprecated in Mule 3 in favor of transforming to a map and using the MEL expressions below.
payload.property
payload.'property'
payload['property']
The reason the first fails in your case, is beacaue of the special character '_'. The underscore forces the field name to be wrapped in quotes.
Typically the . notation is preferred over the [''] as its shorter for accessing map fields. And then simply wrap property names in '' for any fields with special chars.
Note in Mule 4, you don't need to transform to a map/object first. Dataweave expression replace MEL as the expression language and allow you to directly query json or any type of payload without transforming to a map first.
I am trying to process a dataset with JSON data. However, the data have been written on a file without being parsed. That means that a python dictionary is written in the file as a string instead of a JSON object as a string.
I've found a module (AST) that will do the job to convert the string to a dictionary again using the ast.literal_eval function.
However, I am getting a very strange error in some of the instances:
The code reads from a text file and apply the following to each line:
ast.literal_eval(line.rstrip())
It seems some of the characters are not ok with the AST module.
Need to recall as well that this is not happening with all the dataset, just with some instances.
Any ideas?
Many thanks in advance.
Try exploring the json package. It is cleaner and more standard way of converting strings to dictionary
json.loads(inputStr) // Converts string -> dict
json.dumps(inputJson) // Converts dict -> string
Hope this helps. Cheers!
I'm using noflo and am trying to send an array as an initiallizer. There doesn't seem to be a supported (or at least documented) way to do this.
I'm currently using:
'["Kicker"]' -> IN Nodes(strings/ParseJson)
'{"in":"go!"}' -> IN Config(strings/ParseJson)
Nodes() OUT -> NODES MyComponent(noflotest/Universe)
Config OUT -> CONFIG MyComponent()
Is there a better way to do this?
Currently arrays and other complicated data structures are not supported in the .fbp syntax. There is a feature request about this.
Right now you have three options:
If FBP parser accepts your string (see the matching rules), you can first send it to the strings/ParseJson component to turn it to the appropriate data structure
Reading the value from a JSON or YAML file and passing it through the appropriate parser component
Converting your graph to the JSON graph format