Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

how can i parsing json array and create the table on sql server

Hello,

 In fact, I just started working with talend open studio for data integration; I want to export a array long json and I want to transform the data coming from JSON by using talend to organize and store them in a sql database and sqlserver

It is necessary that the data in the JSON file be structured in a mysql database according to the same division so I need to load JSON files periodically in a table sql(insert in the same table) in the SQL Server database. Can you explain to me which components with which configuration and  schema I can use?

How I would like the output to look like:

CVE Scope debainbug description status fixed_version urgency
             

I attach one part short  my jsonfille : https://security-tracker.debian.org/tracker/data/json

I thank you in advance.

I use "Talend open studio for data integration version 7.1.1.2018102681147

 

Thank you very much for your time and help

Best regard0683p000009M4Fw.png0683p000009M4G6.png0683p000009M3U3.png0683p000009M4GG.png0683p000009M4GL.png

Labels (1)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

I've looked into this and have found that your JSON is of an irregular structure. You seem to have CVEs that are grouped together with other CVEs. If you consume your data using a tFileInputJSON and have the following configuration....

0683p000009M48o.png

....then connect the output to a tLogRow, you will see a couple of thousand JSON sub sections. They all appear to be individual CVE sections (and some are), but if you look deeper you will see that some are grouped together. The rule is needed for this.

I've written some Java to pull the sub CVE sections out of the groups. This showed me that the debianbug field does not always appear. The code I used can be seen below....

	public static ArrayList<String> getSubJSON(String json) {
		ArrayList<String> returnArray = new ArrayList<String>();
		try {
			JSONObject obj = new JSONObject(json);
			 java.util.Iterator<String> it = obj.keys();
			 
			 while(it.hasNext()) {
				 String key = (it.next()).toString();
				 
				 returnArray.add("{\""+key+"\":"+obj.get(key).toString()+"}");
				 
			 }
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return returnArray;
		
	}

You will need the following imports...

import org.json.*;
import java.util.ArrayList;

....and will need to import the java-json.jar into your routine to compile the above code.

 

I used the above code to pull out the grouped CVE sections and got the result which I have added in the attached file.

 

Before you can get any further with this, you will need to work out why the structure is as it is. Once you know this, you will need to use a bit of Java to pull out the CVE names, since dynamic JSON is not handled very well by the standard components. The code I have given you shows how to achieve this though.

 

I shall be away on holiday for the next week, but hopefully you can extrapolate from this (or someone else can follow this and fill in any blanks I may have left).

 

Good luck.


JSON_Objects.txt

View solution in original post

12 Replies
Anonymous
Not applicable
Author

1. you first extract data from your json file as you show it in the image. 

You can test using tlogrow

 

2. you create database connection and test that the connection is working correctly

 

3. last step tDBOutput

 

 


DBconnection.PNG
Anonymous
Not applicable
Author

hello;

I managed to connect my database on sqlserver but my problem is on the data extraction with tJsonExtart components, I could not extract correct and it displays the colouns null

How I would like the output to look like:

CVE Scope debainbug description status fixed_version urgency
           

0683p000009M4Ga.png0683p000009M4Gk.png0683p000009M4Bv.png0683p000009M448.png0683p000009M3Sd.png


inputfille.docx
Anonymous
Not applicable
Author

hello;

I managed to connect my database on sqlserver but my problem is on the data extraction with tJsonExtart components, I could not extract correct and it displays the colouns null

How I would like the output to look like:

CVE Scope debainbug description status fixed_version urgency
           

0683p000009M4Ga.png0683p000009M4Gk.png0683p000009M4Bv.png0683p000009M448.png0683p000009M3Sd.png


inputfille.docx
inputfille.docx
Anonymous
Not applicable
Author

hello;

I managed to connect my database on sqlserver but my problem is on the data
extraction with tJsonExtart components, I could not extract correct and it
displays the colouns null

How I would like the output to look like:
CVE Scope debainbug description status fixed_version urgency



Anonymous
Not applicable
Author

I've looked into this and have found that your JSON is of an irregular structure. You seem to have CVEs that are grouped together with other CVEs. If you consume your data using a tFileInputJSON and have the following configuration....

0683p000009M48o.png

....then connect the output to a tLogRow, you will see a couple of thousand JSON sub sections. They all appear to be individual CVE sections (and some are), but if you look deeper you will see that some are grouped together. The rule is needed for this.

I've written some Java to pull the sub CVE sections out of the groups. This showed me that the debianbug field does not always appear. The code I used can be seen below....

	public static ArrayList<String> getSubJSON(String json) {
		ArrayList<String> returnArray = new ArrayList<String>();
		try {
			JSONObject obj = new JSONObject(json);
			 java.util.Iterator<String> it = obj.keys();
			 
			 while(it.hasNext()) {
				 String key = (it.next()).toString();
				 
				 returnArray.add("{\""+key+"\":"+obj.get(key).toString()+"}");
				 
			 }
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return returnArray;
		
	}

You will need the following imports...

import org.json.*;
import java.util.ArrayList;

....and will need to import the java-json.jar into your routine to compile the above code.

 

I used the above code to pull out the grouped CVE sections and got the result which I have added in the attached file.

 

Before you can get any further with this, you will need to work out why the structure is as it is. Once you know this, you will need to use a bit of Java to pull out the CVE names, since dynamic JSON is not handled very well by the standard components. The code I have given you shows how to achieve this though.

 

I shall be away on holiday for the next week, but hopefully you can extrapolate from this (or someone else can follow this and fill in any blanks I may have left).

 

Good luck.


JSON_Objects.txt
Anonymous
Not applicable
Author

I thank you very much for your answer and your time; I will test what you say
have a nice trip

Anonymous
Not applicable
Author

first of all thank you for your answer, I saw your code and what extract .
I tried to do the steps you said, first I created a new routine and added the code and then added it in tmap but it displays this error Mismatch type: cannot convert from ArrayList<String> to String talend
I add the pictures of d; in any case I can't extract the data and it still displays null in tlogrow .
in addition, on the one hand I don't know how I configure tExtractjsonfields
On the other hand I tried to use in Talend the cves file you attached but it just gives me a CVE
do you have any advice for my problem?

0683p000009M4Q6.png0683p000009M4QB.png0683p000009M4H5.png0683p000009M4Ok.png0683p000009M4QG.png0683p000009M4QL.png

Anonymous
Not applicable
Author

Thank you very much for your answer

can you explain to me how to use the code with screenshot job and component configuration
Thank you very much.

Anonymous
Not applicable
Author

I change my job and I have successfully extracted the tables and saved in my database servers with other code but I have a problem I don't know why the column debainbug is null in case in my tfileinputjson it has values but in textractjsonField it is null
I attach all the configuration photos of my components and the code; can someone help me?
thanks

0683p000009M56B.png0683p000009M56G.png0683p000009Lzhk.png0683p000009M55x.png0683p000009M4gP.png0683p000009M56u.png