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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
microwin88x
Creator III
Creator III

Split Big String in Multiple Fields?

Hi,

I have the following string:

[{"id":"1","program":"prog003","number":"100","datetime":"2017-01-03","zone":"north","amount":"100"}, {"id":"2","program":"prog003","number":"200","datetime":"2017-01-04","zone":"north","amount":"300"}, {"id":"3","program":"prog004","number":"300","datetime":"2017-01-05","zone":"south","amount":"150"},{"id":"4","program":"prog004","number":"400","datetime":"2017-01-03","zone":"east","amount":"500"},{"id":"5","program":"prog005","number":"500","datetime":"2017-01-04","zone":"west","amount":"450"},{"id":"6","program":"prog006","number":"600","datetime":"2017-01-05","zone":"east","amount":"200"},{"id":"7","program":"prog007","number":"700","datetime":"2017-01-06","zone":"west","amount":"150"},{"id":"8","program":"prog007","number":"800","datetime":"2017-01-07 ","zone":"south","amount":"200"}]

I need to use String Functions by script in order to get a table with the following:

idprogramnumberdatetimezoneamount
1prog0031002017-01-03north100
2prog0032002017-01-05north300
3prog0043002017-01-05south150
..................

Is there any way to split it with functions by script so I could have this?

Thanks!

4 Replies
Anil_Babu_Samineni

Where this JSON format stored. I mean Txt or what?

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
microwin88x
Creator III
Creator III
Author

It's a URL. But the thing is I would need to use String Functions like SubField/TextBetween/etc because I was asked to do it that way instead of using macros or other connectors... Do you know how could I do that?

MarcoWedel

Hi,

besides a "real" JSON parser being the best solution for this requirement, a script-only solution for this specific source data could be:

QlikCommunity_Thread_253957_Pic1.JPG

tabTemp:

Generic

LOAD ID,

     SubField(SubString,'"',2),

     SubField(SubString,'"',4);

LOAD SubField(TextBetween(BigString,'{','}',IterNo()),',') as SubString,

     IterNo() as ID

Inline [

BigString

{"id":"1","program":"prog003","number":"100","datetime":"2017-01-03","zone":"north","amount":"100"}, {"id":"2","program":"prog003","number":"200","datetime":"2017-01-04","zone":"north","amount":"300"}, {"id":"3","program":"prog004","number":"300","datetime":"2017-01-05","zone":"south","amount":"150"},{"id":"4","program":"prog004","number":"400","datetime":"2017-01-03","zone":"east","amount":"500"},{"id":"5","program":"prog005","number":"500","datetime":"2017-01-04","zone":"west","amount":"450"},{"id":"6","program":"prog006","number":"600","datetime":"2017-01-05","zone":"east","amount":"200"},{"id":"7","program":"prog007","number":"700","datetime":"2017-01-06","zone":"west","amount":"150"},{"id":"8","program":"prog007","number":"800","datetime":"2017-01-07 ","zone":"south","amount":"200"}

] (delimiter is '\t')

While IterNo()<=SubStringCount(BigString,'{');

tabResult:

LOAD 1 AutoGenerate 0;

FOR i = NoOfTables()-1 to 0 STEP -1

  LET vTable=TableName($(i));

  IF WildMatch('$(vTable)', 'tabTemp.*') THEN

  JOIN (tabResult) LOAD * RESIDENT [$(vTable)];

  DROP TABLE [$(vTable)];

  ENDIF

NEXT i

DROP Field 1;

hope this helps

regards

Marco

MarcoWedel

please close your thread if your question is answered:

Qlik Community Tip: Marking Replies as Correct or Helpful

thanks

regards

Marco