Solved

Parse json in a task

  • 21 December 2022
  • 3 replies
  • 92 views

Userlevel 5
Badge +12

Hi,

I would like to process some json content. The code I have to process it works quite well, except that I do not know how to access the file in the gui. 

I currently have a task, with a file upload and a Functionality. This func. writes the json data into the db. 

However, instead of the contents of the file, it tried to process the filename, not the contents. 

Also, I would like to handle the file without uploading and storing it in Azure, since I do not need the file afterwards. 

Any guidance in this would be very welcome. 

Thanks, 

Alexander 

icon

Best answer by Mark Jongeling 21 December 2022, 21:53

View original

This topic has been closed for comments

3 replies

Userlevel 7
Badge +23

Hi Alexander,

You could make a Process flow that starts with a Start (table) task process action. That task should have two task parameters, one for the file name (domain with file upload - Database storage type) and one for its file data. These parameters can then be linked with process variables.

Now you have the file data inside the process variable and you can do anything with it.

Hope this helps!

Userlevel 5
Badge +12

Hi Mark, 

Well, I have a PF that does something. 1 start task - upload file. 
Task 2 - with a template to process the file. 

But the var ‘file_content’ is now - according to the PF monitor set with value ‘System.Byte[]’ and the code processing the data states; 

JSON text is not properly formatted. Unexpected character '祓' is found at position 0.
or, we fiddling;  Unexpected character 'ൻ' is found at position 0.

So, somewhere something is off, since i’m not formatting an asian language..

I have two vars. 1 file_upload (databse), 1 file_content. he domain for this var is a varbinary(max).

Quite lost on this. 

Also, I don’t see the file/data in my db. I have made a table for this, with 3 columns. PK, file_name, file_content. Yet.. no records. Where/how can I spec that the file needs to go in said table? 
 

Userlevel 7
Badge +23

Could it be that you try to convert the data into nvarchar(max)? If you make that varchar(max) instead, does that solve it?

The Task will not automatically add it to your table, you’ll have to write the insert into statement for it, using the variables as select values. E.g.:

insert into json_table
(
file_name,
file_data,
file_data_in_text
)
select
@file_name,
@file_data,
convert(varchar(max), @file_data)