Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
WSyahirah21
Creator
Creator

JSONObject text must begin with '{' at 1 [character 2 line 1]

I am creating a workflow to extract the json string from spark job in the tSystem using tJava:

tSystem -> tJava 

 

Expected output is, firstly, tSystem will give the string result in the form of log.info() and also in json format. Later, tJava will extract and only print out the json string while ignore the other string format. 

 

Spark output from tSystem:

String output=((String)globalMap.get("tSystem_3_OUTPUT"));

JSONObject jsonObject = new JSONObject(output);

System.out.println(jsonObject);

String sourceCount=(jsonObject.getString("Source rows"));

System.out.println("Database Name: "+jsonObject.getString("DBName"));

globalMap.put("sourceCount",sourceCount.trim());

 

However, when I run my current workflow, the following error appears which I believe is because my java code in tJava tried to read the string in all format , instead of json string only. 

 

Error in tJava:

FATAL] 11:18:46 nerve_ingestion.fullrefreshingestion_dev_0_15.FullRefreshIngestion_Dev- tJava_3 A JSONObject text must begin with '{' at 1 [character 2 line 1]

routines.system.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]

at routines.system.JSONTokener.syntaxError(JSONObject.java:1790) ~[routines.jar:?]

at routines.system.JSONObject.<init>(JSONObject.java:166) ~[routines.jar:?]

at routines.system.JSONObject.<init>(JSONObject.java:279) ~[routines.jar:?]

 

How should i change the java code to ensure tJava only capture the json string? 

Labels (4)
1 Solution

Accepted Solutions
WSyahirah21
Creator
Creator
Author

Hi jzhao,

Issue solved. Basically I did following step in tJava:

 

  1. Use substring between “ingestion start” and “ingestion end” to capture that json line in spark job result.
  2. Do some cleanup until u get that jsonobject only.

 

Thanks for responding!

View solution in original post

2 Replies
jzhao
Employee
Employee

Hello,

what's the content of "output" ?

WSyahirah21
Creator
Creator
Author

Hi jzhao,

Issue solved. Basically I did following step in tJava:

 

  1. Use substring between “ingestion start” and “ingestion end” to capture that json line in spark job result.
  2. Do some cleanup until u get that jsonobject only.

 

Thanks for responding!