Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
I'm trying to parse the JSON pairs "name" from the below string but none of the combinations I used in tExtractJSON worked (I used both JsonPath and Xpath and nothing works).
{"server_time":1535722727,"pairs":{"eur_usd":{"decimal_places":8,"min_price":0.00000001,"max_price":2.0,"min_amount":0.00000001,"max_amount":1000000.0,"min_total":0.0001,"hidden":0,"fee":0.25},"chf_usd":{"decimal_places":8,"min_price":0.00000001,"max_price":2.0,"min_amount":0.001,"max_amount":1000000000.0,"min_total":0.0001,"hidden":1,"fee":0.25},"jpy_usd":{"decimal_places":8,"min_price":0.00000001,"max_price":2.0,"min_amount":0.001,"max_amount":1000000000.0,"min_total":0.0001,"hidden":1,"fee":0.25}
I'm trying to get just the pairs names: "eur_usd", "chf_usd", "jpy_usd". Any help would be greatly appreciated.
something like:
use tLibrayLoad for - javax.json-api-1.1.2.jar
1st tJavaFlex
import java.util.*; import javax.json.*; JSONObject object = new JSONObject(row4.line); String[] keys = JSONObject.getNames(object); for (String key : keys) { Object value = object.get(key); } globalMap.put("array_size", keys.length); List keylist = Arrays.asList(keys); globalMap.put("vk",keylist);
2nd tJavaFlex:
List<String> alist = (List<String>)globalMap.get("vk"); Integer ii = ((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))-1; globalMap.put("jkey",alist.get(ii));
it iterate over pair and put each key name into global variable for use on feature steps
-- edited
because You need Keys names, it not possible todo with standard Talend components
but possible with tJava
You can search on forum, but I can try to find example from past project
something like:
use tLibrayLoad for - javax.json-api-1.1.2.jar
1st tJavaFlex
import java.util.*; import javax.json.*; JSONObject object = new JSONObject(row4.line); String[] keys = JSONObject.getNames(object); for (String key : keys) { Object value = object.get(key); } globalMap.put("array_size", keys.length); List keylist = Arrays.asList(keys); globalMap.put("vk",keylist);
2nd tJavaFlex:
List<String> alist = (List<String>)globalMap.get("vk"); Integer ii = ((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))-1; globalMap.put("jkey",alist.get(ii));
it iterate over pair and put each key name into global variable for use on feature steps
Thank you for this; this is great!
Hi vapukov,
I have similar question where I need to extract pair_names, values of decimal_places, min_price etc and insert it in the db table, then how do I go about it?
,