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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Pico
Partner - Creator
Partner - Creator

Extract Json field from csv file

Hi there, I have a csv file with 3 columns:

YearMonth Project Distribution
202412 it-secu-01 {"Company1":10,"Company2":30,Company3":50,Company4":20}
202412 de-jkns-04 {"Company1":10,"Company2":10,Company3":0,Company4":80}

 

where "Company1":10 means we have to extract the value 10(%) and associated to Company1.

the expected result would be:

YearMonth Project Company %
202412 it-secu-01 Company1 10
202412 it-secu-01 Company2 30
202412 it-secu-01 Company3 50
202412 it-secu-01 Company4 20
202412 de-jkns-04 Copmany1 10
202412 de-jkns-04 .. ...

 

Right now i have

Table:
LOAD
month, 
projectId, 
cost_percentage;
[total_cost_distribution_table]:
 
SELECT `month`,
projectId,
`cost_percentage`
FROM [DB Object].
 
How can I achieve this without getting crazy with "MID" "LEFT" adn "RIGHT" functions?
Note: I read about the function "JsonGET" gut it seems useless to me. Correct me if I'm wrong
 
Thank you
Labels (3)
1 Solution

Accepted Solutions
QFabian
MVP
MVP

Hi, please check this example : 

QFabian_0-1733741578261.png

This is the example script :

RawData:
Load * INLINE [
YearMonth, Project, Distribution
202412, it-secu-01, "{"Company1":10,"Company2":30,"Company3":50,"Company4":20}"
202412, de-jkns-04, "{"Company1":10,"Company2":10,"Company3":0,"Company4":80}"
];
 
 
Data:
Load 
YearMonth,
Project,
    Distribution,
    subfield(purgechar(Distribution, '{}"'), ',') as Distribution_SemiProcessed
  
Resident RawData;
drop table RawData;
 
Data2:
Load 
YearMonth,
Project,
   Distribution,
   subfield(Distribution_SemiProcessed, ':', 1) as Company,
   subfield(Distribution_SemiProcessed, ':', 2) as [%]
Resident Data;
drop table Data;
 
exit script;

 

 

 

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.

View solution in original post

3 Replies
QFabian
MVP
MVP

Hi, please check this example : 

QFabian_0-1733741578261.png

This is the example script :

RawData:
Load * INLINE [
YearMonth, Project, Distribution
202412, it-secu-01, "{"Company1":10,"Company2":30,"Company3":50,"Company4":20}"
202412, de-jkns-04, "{"Company1":10,"Company2":10,"Company3":0,"Company4":80}"
];
 
 
Data:
Load 
YearMonth,
Project,
    Distribution,
    subfield(purgechar(Distribution, '{}"'), ',') as Distribution_SemiProcessed
  
Resident RawData;
drop table RawData;
 
Data2:
Load 
YearMonth,
Project,
   Distribution,
   subfield(Distribution_SemiProcessed, ':', 1) as Company,
   subfield(Distribution_SemiProcessed, ':', 2) as [%]
Resident Data;
drop table Data;
 
exit script;

 

 

 

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.
QFabian
MVP
MVP

Check Subfield function in Qlik Help:

https://help.qlik.com/en-US/qlikview/May2024/Subsystems/Client/Content/QV_QlikView/Scripting/StringF...

QFabian_1-1733741921445.png

Qlik Help :

QFabian_2-1733741935455.png

🤣

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.
QFabian
MVP
MVP

notice that i had to put a couple of double quoetes for the exercise :

QFabian_3-1733742142139.png

QFabian_4-1733742180797.png

 

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.