Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
AlexOmetis
Partner Ambassador
Partner Ambassador

CSV embedded in JSON

I'm extracting data from the Harvest API. I've got plenty of data out of it, but am struggling with the strange format they output Invoice Lines... it's CSV embedded within JSON or XML - which is a new one on me. This part of the API is documented here.

So how do you turn this value in a JSON response:

kind,description,quantity,unit_price,amount,taxed,taxed2,project_id\nProduct,A description,1.00,100.00,100.0,false,false,\n
into something that Qlik can analyse properly?

Initially I thought it would be fine - just subfield on newline (chr(10)) and then again on comma, but the usual things catch you out - newlines and commas within the data. If there's no new line or comma in a field, it doesn't wrap the contents in quotes, but if there is, it does.

Then I thought perhaps I could store it out to a file and read it back in as a CSV file, but of course Qlik adds its own quotes around things and additional header row when you save to CSV/TXT so that doesn't help.

Of course I could call an external program to do the processing, but I wondered if anyone had a way of doing this within Qlik.

Qlik Partner Ambassador 2024
1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

You can load the JSON with a regular LOAD and afterwards you can LOAD ..... FROMFIELD .... from the field that has the CSV.

Could you provide a sample JSON-file with some CSV embedded and I can give you a working example.

View solution in original post

5 Replies
Anil_Babu_Samineni

I got 90% which you explained. Still doubt what you are trying? And can i know simple way to do in Qlik where you are expecting

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
AlexOmetis
Partner Ambassador
Partner Ambassador
Author

I get one of those CSV-formatted strings in the JSON record for each invoice, detailing the lines in the invoice. I'd like to end up with a table with Invoice ID (which I can get from the header just fine) and then kind, description, quantity etc as fields. It'd be easy if it was in files, but it's being embedded in JSON that makes it tricky.

Qlik Partner Ambassador 2024
petter
Partner - Champion III
Partner - Champion III

You can load the JSON with a regular LOAD and afterwards you can LOAD ..... FROMFIELD .... from the field that has the CSV.

Could you provide a sample JSON-file with some CSV embedded and I can give you a working example.

AlexOmetis
Partner Ambassador
Partner Ambassador
Author

Fantastic - had never come across that before, but that's sorted it - thanks very much.

(Although worth noting it's FROM_FIELD not just FROMFIELD)

Qlik Partner Ambassador 2024
petter
Partner - Champion III
Partner - Champion III

It seems to be very slow though... Haven't used it on very large amounts of data but the experience so far is that it is *slow* - the FROM_FIELD loading not JSON.