Ast.literal_eval is throwing error for large text file

Hi,

I am using named query to fetch data from database.

when use ast.literal_eval for the data its throwing error. because data i am getting is too large.

how to handle this?

WO_Data = woline.getValueAt(0,0)
			
WO_Detail = ast.literal_eval(system.util.jsonDecode(WO_Data)[0])

large file.txt (152.8 KB)

Don't use literal_eval for this (whatever this is) ! Where did you get that idea ?

What are you trying to achieve ? jsonDecode already returns a python datastructure, so I'm really not sure where you're going with this.

This json contains KPI values that i am fetching and writing to the tags

So you have a dataset that contains json which contains values ?

If you remove the literal_eval part, you'll get a data structure, likely a list of dicts, where you'll get your data. How you use it then is up to you.

If don't use Ast.literal
i am getting this error. while processing the data

Traceback (most recent call last):
File "", line 45, in
TypeError: str indices must be integers

if i use Ast.literal this working fine

If it works fine with eval_literal, you're doing something wrong. But if it was working fine, you wouldn't be asking for help.
I repeat: DO NOT use it. If you get an error when trying to access your datastructure, fix how you're accessing it. Using eval_literal is NOT a fix.
Just to give you some context: "ast" means Abstract Syntax Tree. It is used to handle code, NOT json.

So, back to your error. It seems you're trying to access a list element with a key instead of an index. That's what you need to fix.

If you want more help, we'll need more details.

1 Like