Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
zalibra
Contributor III
Contributor III

Unable to parse JSON "name" using tExtractJSON

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. 

Labels (3)
1 Solution

Accepted Solutions
vapukov
Master II
Master II

something like:

 

0683p000009M0D5.png

 

 

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));

0683p000009M0DO.png

 

it iterate over pair and put each key name into global variable for use on feature steps

0683p000009M0HU.png

 

View solution in original post

4 Replies
vapukov
Master II
Master II

-- 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

vapukov
Master II
Master II

something like:

 

0683p000009M0D5.png

 

 

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));

0683p000009M0DO.png

 

it iterate over pair and put each key name into global variable for use on feature steps

0683p000009M0HU.png

 

zalibra
Contributor III
Contributor III
Author

Thank you for this; this is great!

JYeola
Contributor
Contributor

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?

,