Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to change the structure when converting from CSV file to json file

Hi.

 

I am creating on converting CSV file to JSON file job.

 

My CSV Format:

 

Product,Price,Quantity
"ABC",100,10
"DEF",200,20

Json file format I need:

 

 

{
    "app" : 1,
    "records" : [  
            {
                "Product" : { "value" : "ABC"},
                "Price" : { "value" : 100},
                "Quantity" : { "value" : 10}    
            },
            {
                "Product" : { "value" : "DEF"},
                "Price" : { "value" : 200},
                "Quantity" : { "value" : 20}    
            }
    ]
}

I have completed this:

 

 

{
    "records" : [  
            {
                "Product" : "ABC",
                "Price" :  100,
                "Quantity" : 10    
            },
            {
                "Product" : "DEF",
                "Price" : 200,
                "Quantity" : 20    
            }
    ]
}

How can I add an "app" property to the route and include "value" property?

 

The “1” property data can be a static value.

 

My job setting (sorry, it's not the English version.):

All schemas are built-in and default settings.

0683p000009M76R.png0683p000009M76W.png

Thank you.

Labels (5)
1 Solution

Accepted Solutions
JR1
Creator III
Creator III

OK, Let's do this. You can achieve this by doing it in two stages.

Build a job that looks like the one below. In the first tWriteJSONField you create a JSON object for each row (pay attention to all the settings!).

0683p000009M775.jpg

In a tMap you simply add a new column called "app" and map the output of the previous step to a column called "records".

0683p000009M77F.jpg

Then move the output into another tWriteJSONField component and configure it as follows (the output has just one column named "content"):

0683p000009M6uq.jpg

Finally, store your output in a file (or do whatever you want to do with it.

0683p000009M77K.jpg

 

When I put the following input into the tFixedFlowInput (Product is a String, Price is an Integer, Quantity is an Integer - of course you could also use a CSV file as input)

Product,Price,Quantity
"ABC",100,10
"DEF",200,20

I get the following output

{"app":1,"records":[{"product":{"value":"ABC"},"price":{"value":100},"quantity":{"value":10}},{"product":{"value":"DEF"},"price":{"value":200},"quantity":{"value":20}}]}

I hope this helps.

View solution in original post

7 Replies
JR1
Creator III
Creator III

OK, Let's do this. You can achieve this by doing it in two stages.

Build a job that looks like the one below. In the first tWriteJSONField you create a JSON object for each row (pay attention to all the settings!).

0683p000009M775.jpg

In a tMap you simply add a new column called "app" and map the output of the previous step to a column called "records".

0683p000009M77F.jpg

Then move the output into another tWriteJSONField component and configure it as follows (the output has just one column named "content"):

0683p000009M6uq.jpg

Finally, store your output in a file (or do whatever you want to do with it.

0683p000009M77K.jpg

 

When I put the following input into the tFixedFlowInput (Product is a String, Price is an Integer, Quantity is an Integer - of course you could also use a CSV file as input)

Product,Price,Quantity
"ABC",100,10
"DEF",200,20

I get the following output

{"app":1,"records":[{"product":{"value":"ABC"},"price":{"value":100},"quantity":{"value":10}},{"product":{"value":"DEF"},"price":{"value":200},"quantity":{"value":20}}]}

I hope this helps.

Anonymous
Not applicable
Author

Thanks for reply.

 

I tried it.

But, "Output Column" is empty.

Is something wrong?

0683p000009M78I.png

 

tFixedFlowInput settings:

0683p000009M78N.png

 

 

tFixedFlowInput schema settings:

0683p000009M6ur.png

 

Result of confirming tFixedFlowInput output with tLogRow(Table mode):

[statistics] connecting to socket on port 3712
[statistics] connected
.--------+-----+--------.
|       tLogRow_1       |
|=-------+-----+-------=|
|Product |Price|Quantity|
|=-------+-----+-------=|
|Product1|100  |10      |
|Product2|200  |20      |
'--------+-----+--------'

[statistics] disconnected

Thanks.

JR1
Creator III
Creator III

Click on "Edit Schema" in tWriteJSONField and add the missing output column on the right side?

Anonymous
Not applicable
Author

Oh, I did not...

I set it like this now:

0683p000009M78J.png

Then, three items will be displayed.
How do I display content only?

0683p000009M6g4.png

 

Thank you.

JR1
Creator III
Creator III

You will have to remove the three columns just from the right side of the schema and just add a single column there (e.g. "content"). Do not use the arrows in the middle to move columns between the schemas.

Anonymous
Not applicable
Author

Thank you very much.
It is almost completed, but I want you to help at the end.

When setting to your answers, the final output looks like this.

 

 

{"app":1,"records":{"Product":{"value":"Product1"},"Price":{"value":100},"Quantity":{"value":10}}}
{"app":1,"records":{"Product":{"value":"Product2"},"Price":{"value":200},"Quantity":{"value":20}}}

I've checked your screenshots many times, but I don't know what's wrong.

 

tMap mapping:

0683p000009M78X.png

 

tMap component setting:

0683p000009M78c.png

 

 

 

tWriteJSONField2 schema setting:
0683p000009M6jD.png

 

 

 

 

 

 

 

 

 

 

 

tWriteJSONField2 setting:

0683p000009M78m.png

 

tWriteJSONField2 JSON tree setting:

0683p000009M78r.png

 

Thank you.

 

JR1
Creator III
Creator III

You are missing the "Group By" settings in tWriteJSONField_2.