# Json to tags directly using script console but not really working as intended

**URL:** <https://forum.inductiveautomation.com/t/json-to-tags-directly-using-script-console-but-not-really-working-as-intended/108471>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 15, 2025, 1:32pm UTC](https://forum.inductiveautomation.com/t/json-to-tags-directly-using-script-console-but-not-really-working-as-intended/108471 "2025-07-15T13:32:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh.upadhyay](https://avatars.discourse-cdn.com/v4/letter/u/a88e57/32.png) [@utkarsh.upadhyay](https://forum.inductiveautomation.com/u/utkarsh.upadhyay)\
**Post date:** [July 15, 2025, 1:32pm UTC](https://forum.inductiveautomation.com/t/json-to-tags-directly-using-script-console-but-not-really-working-as-intended/108471/1 "2025-07-15T13:32:01Z")

</div>

Hey Forum, I am back with another question

I have a nested Json and i am trying to form tags and folder structure from it directly but its not working for the nested part have no idea why

```python
import json
import re
import time
 
# Sample JSON data
json_data = '''{
  "valve": {
    "id": "VALV12345",
    "type": "Ball Valve",
    "size_in_inches": 2,
    "material": "Stainless Steel",
    "pressure_rating_psi": 600,
    "connection_type": "Flanged",
    "actuation_type": "Manual",
    "manufacturer": "FlowTech Industries",
    "model_number": "FT-BV600-2SS",
    "installation_date": "2023-08-15",
    "last_maintenance_date": "2025-06-10",
    "status": "Operational",
    "location": {
      "plant": "Chennai Plant 3",
      "section": "Cooling Line A",
      "coordinates": {
        "latitude": 13.0827,
        "longitude": 80.2707
      }
    },
    "notes": "No issues reported during last inspection."
  }
}'''
 
# Parse JSON
data = json.loads(json_data)
valve_data = data["valve"]
valve_id = valve_data["id"]
base_path = "[default]Utkarsh_Valves/" + valve_id
 
# Detect datatype
def detect_datatype(value):
    if isinstance(value, bool):
        return "Boolean"
    elif isinstance(value, int):
        return "Int4"
    elif isinstance(value, float):
        return "Float8"
    elif isinstance(value, str):
        if re.match(r"\d{4}-\d{2}-\d{2}", value):
            return "Date"
        else:
            return "String"
    else:
        return "String"
 
# Recursive tag builder
def build_tags(data_dict):
    tags = []
    for key, value in data_dict.items():
        if isinstance(value, dict):
            tags.append({
                "name": key,
                "type": "Folder",
                "tags": build_tags(value)
            })
        else:
            tags.append({
                "name": key,
                "type": "Memory",
                "datatype": detect_datatype(value),
                "value": value
            })
    return tags
 
# ⛔ Step 1: Delete base path fully
if system.tag.exists(base_path):
    system.tag.deleteTags([base_path])
    time.sleep(0.5) # Optional wait to allow deletion to finish
 
# ✅ Step 2: Build new tag structure excluding 'id'
tag_structure = build_tags({k: v for k, v in valve_data.items() if k != "id"})
 
# ✅ Step 3: Create the new tag structure
system.tag.configure(base_path, tag_structure, overwrite=True)

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 16, 2025, 5:19pm UTC](https://forum.inductiveautomation.com/t/json-to-tags-directly-using-script-console-but-not-really-working-as-intended/108471/3 "2025-07-16T17:19:10Z")

</div>

You can't use type for a folder.

Change `"type": "Folder"` to `"tagType": "Folder"`

References:

> **[system.tag.configure | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-configure#code-examples)**
>
> Creates tags from a given list of Python dictionaries or from a JSON source string.

> **[Scripting Object Reference | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/reference-pages/scripting-object-reference#all-nodes-tags-folders-udt-definitions-and-udt-instances)**
>
> This page describes several common scripting objects

---

<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:** [July 16, 2025, 6:54pm UTC](https://forum.inductiveautomation.com/t/json-to-tags-directly-using-script-console-but-not-really-working-as-intended/108471/4 "2025-07-16T18:54:56Z")

</div>

My GPTdar is beeping so hard at this code !

Here's the structure you want:

```python
{
	'name': key,
	'dataType': detect_datatype(value),
	'tagType': "AtomicTag",
	'valueSource': "memory",
}

{
	'name': key,
	'tagType': "Folder",
	'tags': build_tags(value)
}

```

Also note that:

- the `dataType` for dates is `DateTime`, not `Date`.
- `system.tag.configure` doesn't take an `overwrite` parameter. It takes `collisionPolicy`, which can have a value of `"o"` for overwrite.
- You should be using `system.util.jsonEncode` and `system.util.jsonDecode` instead of importing `json`.
- And why are you creating a json string, to then parse it ? Just make a dict !
- I really doubt the `sleep` is justified.

Here's the code you need. But you should really, REALLY read the doc instead of blindly trusting an AI.

```python
import re
 
data = {
	"valve": {
		"id": "VALV12345",
		"type": "Ball Valve",
		"size_in_inches": 2,
		"material": "Stainless Steel",
		"pressure_rating_psi": 600,
		"connection_type": "Flanged",
		"actuation_type": "Manual",
		"manufacturer": "FlowTech Industries",
		"model_number": "FT-BV600-2SS",
		"installation_date": "2023-08-15",
		"last_maintenance_date": "2025-06-10",
		"status": "Operational",
		"location": {
			"plant": "Chennai Plant 3",
			"section": "Cooling Line A",
			"coordinates": {
				"latitude": 13.0827,
				"longitude": 80.2707
			}
		},
		"notes": "No issues reported during last inspection."
	}
}
 
valve_data = data["valve"]
valve_id = valve_data["id"]
base_path = "[default]Utkarsh_Valves/" + valve_id
 
# Detect datatype
def detect_datatype(value):
	if isinstance(value, bool):
		return "Boolean"
	elif isinstance(value, int):
		return "Int4"
	elif isinstance(value, float):
		return "Float8"
	elif isinstance(value, str):
		if re.match(r"\d{4}-\d{2}-\d{2}", value):
			return "DateTime"
		else:
			return "String"
	else:
		return "String"
 
# Recursive tag builder
def build_tags(data_dict):
	tags = []
	for key, value in data_dict.items():
		if isinstance(value, dict):
			tags.append({
				"name": key,
				"tagType": "Folder",
				"tags": build_tags(value)
			})
		else:
			tags.append({
				"name": key,
				"tagType": "AtomicTag",
				"dataType": detect_datatype(value),
				"valueSource": "memory",
				"value": value
			})
	return tags
 
if system.tag.exists(base_path):
	system.tag.deleteTags([base_path])
 
tag_structure = build_tags({k: v for k, v in valve_data.items() if k != "id"})

system.tag.configure(base_path, tag_structure, "o")

```

---

<div class="post-metadata">

**Author:** ![utkarsh.upadhyay](https://avatars.discourse-cdn.com/v4/letter/u/a88e57/32.png) [@utkarsh.upadhyay](https://forum.inductiveautomation.com/u/utkarsh.upadhyay)\
**Post date:** [July 17, 2025, 4:22am UTC](https://forum.inductiveautomation.com/t/json-to-tags-directly-using-script-console-but-not-really-working-as-intended/108471/5 "2025-07-17T04:22:09Z")

</div>

Thank you for your time and guidance will keep that in mind moving forward regarding that can I get the doc link for reference

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 17, 2025, 12:01pm UTC](https://forum.inductiveautomation.com/t/json-to-tags-directly-using-script-console-but-not-really-working-as-intended/108471/6 "2025-07-17T12:01:18Z")

</div>

> [@utkarsh.upadhyay](#):
>
> regarding that can I get the doc link for reference

Link to system scripting functions:

> **[System Functions | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions)**
>
> The Ignition scripting API, which is available under the module name system, is full of functions that are useful when designing projects in Ignition. From running database queries, manipulating components, to exporting data, scripting functions can...

Link to General Manual

> **[Welcome | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/intro)**
>
> About this Manual
