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

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Manipulate JSON input file to remove additional string characters

Hi,

I have the following json file (tfileinputRaw input file )

Input :

[{"_comp":"1","Name":"ABC"} ,
{"_comp":"1","Name":"ZYX"} ,
{"_comp":"1","Name":"MNO"},
{"_comp":"1","Name":"YZX"}]

Output : Expected 

{"_comp":"1","Name":"ABC"}
{"_comp":"1","Name":"ZYX"}
{"_comp":"1","Name":"MNO"}
{"_comp":"1","Name":"YZX"}

 

My requirement is

1. To remove the square brackets [] at the start and end of the file. (There can be square brackets inside the file at other places, it has to be left untouched; only if there is any square brackets at start and end of the file it has to be removed if there is no square brackets it can be left as it is)

2. To remove comma (,) after each record is done.

  New records can be identified whenever {"_comp": is encountered.

So I plan the job to be

tfileinputRaw ==> tjava ==>tfileoutputRaw

in tjava logic planned => if there is , (comma) or [ (open square brackets) before {"_comp": then it has to be replaced with space else do no changes. Also remove ] (close square brackets) at EOF if present, if not present nothing else to be done.

Please help me how to implement this logic in tjava.

 

Labels (4)
11 Replies
TRF
Champion II
Champion II

@tsreenath, does this helps ?
Anonymous
Not applicable
Author

{
"payload": "{
\"state\":{
\"desired\":{
\"uiud\":\"F0038C95FF5C91820\",
\"led\":1536768996,
}
}
}"
}