# Ast.literal\_eval is throwing error for large text file

**URL:** <https://forum.inductiveautomation.com/t/ast-literal-eval-is-throwing-error-for-large-text-file/94999>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [August 22, 2024, 9:07am UTC](https://forum.inductiveautomation.com/t/ast-literal-eval-is-throwing-error-for-large-text-file/94999 "2024-08-22T09:07:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [August 22, 2024, 9:07am UTC](https://forum.inductiveautomation.com/t/ast-literal-eval-is-throwing-error-for-large-text-file/94999/1 "2024-08-22T09:07:32Z")

</div>

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?

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

```

[large file.txt](https://forum.inductiveautomation.com/uploads/short-url/ylkamO5zuEyyu7TeCodibqd4MU4.txt) (152.8 KB)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 22, 2024, 11:08am UTC](https://forum.inductiveautomation.com/t/ast-literal-eval-is-throwing-error-for-large-text-file/94999/2 "2024-08-22T11:08:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [August 22, 2024, 11:43am UTC](https://forum.inductiveautomation.com/t/ast-literal-eval-is-throwing-error-for-large-text-file/94999/3 "2024-08-22T11:43:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 22, 2024, 12:26pm UTC](https://forum.inductiveautomation.com/t/ast-literal-eval-is-throwing-error-for-large-text-file/94999/4 "2024-08-22T12:26:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [August 22, 2024, 12:33pm UTC](https://forum.inductiveautomation.com/t/ast-literal-eval-is-throwing-error-for-large-text-file/94999/5 "2024-08-22T12:33:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 22, 2024, 12:46pm UTC](https://forum.inductiveautomation.com/t/ast-literal-eval-is-throwing-error-for-large-text-file/94999/6 "2024-08-22T12:46:33Z")

</div>

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.
