# Help cleaning code

**URL:** <https://forum.inductiveautomation.com/t/help-cleaning-code/111105>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [September 30, 2025, 3:59pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105 "2025-09-30T15:59:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielps1818](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@danielps1818](https://forum.inductiveautomation.com/u/danielps1818)\
**Post date:** [September 30, 2025, 3:59pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105/1 "2025-09-30T15:59:44Z")

</div>

Hi!

```python
def funct(json):

	if json.get("tagPath"):
		tag_path = json.get("tagPath") + "/" + json.get("name")
		base_path = "[" + conf.default_prov + "]" + json.get("tagPath")
	else:
		tag_path = json.get("name")
		base_path = "[" + conf.default_prov + "]"

```

Any idea on doing this in a cleaner way?  
Not liking much the _double if_

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 30, 2025, 4:05pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105/2 "2025-09-30T16:05:58Z")

</div>

I only see one if/else? Which isn’t bad or complex or something that tells me code immediately needs to be refactored.

Regardless, I am partial to string formatting now via `.format`so I would write this  
`base_path = "[" + conf.default_prov + "]"`

like

`base_path = "[{default}]".format(default=conf.default_prov)`.

You could use a ternary operator if you like those though it might be very wordy and I am not sure it actually makes it cleaner.

`tag_path = ‘{tag_path}/{name}’.format(tag_path=json.get(‘tagPath’), name=json.get(‘name’) if json.get(‘tagPath’) else json.get('name')`

Is your else clause correct? You define tag\_path but then don’t use it. How do they get combined at the end? Feels like you could probably do your tag\_path and base\_path in ternary operators but again - I don’t think that always makes code cleaner or more readable.

Only other thing I would say - pick one, snake\_case or camelCase, it looks like you use both.

---

<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:** [September 30, 2025, 4:33pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105/3 "2025-09-30T16:33:00Z")

</div>

I would do something like this:

```python
def funct(json):
    tagPath = json.get('name')
    basePath = '[{}]'.format(conf.default_prov)

    if json.get('tagPath'):
        tagPath = '{}/{}'.format(json.get('tagPath'),tagPath)
        basePath += json.get('tagPath')

```

Also, I prefer camelCase in jython, because it is the Java standard and because snake\_case makes my eye twitch. It doesn't really matter, but it helps with continuity when you're using Java classes, plus that is the standard that IA uses with their scripting functions.

---

<div class="post-metadata">

**Author:** ![danielps1818](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@danielps1818](https://forum.inductiveautomation.com/u/danielps1818)\
**Post date:** [September 30, 2025, 4:34pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105/4 "2025-09-30T16:34:10Z")

</div>

> [@bkarabinchak.psi](#):
>
> Only other thing I would say - pick one, snake\_case or camelCase, it looks like you use both.

Thx for you answer, it actually helped me decide on how to do it!

About the different types, we use snake\_case, but I have to use camelCase because I'm working with tags, and the tags use camelCase. So all my code is snake\_case except for the values on the dictionary that are meant to work with tags.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 30, 2025, 4:50pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105/5 "2025-09-30T16:50:54Z")

</div>

Throwing my hat in the ring (this does something _slightly_ different to your initial sample, in that it always appends `name` to the path, but that seems likely to be what you want anyways):

```python
def funct(json):
	pathParts = [
		json.get("tagPath"),
		json.get("name"),
	]

	path = "[{provider}]{path}".format(
		provider=conf.default_prov, 
		path="/".join(filter(None, pathParts))
	)

```

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 30, 2025, 5:05pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105/6 "2025-09-30T17:05:13Z")

</div>

What would be the point of applying a `filter` of `None`? Is that just a placeholder you create out of habit?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 30, 2025, 5:07pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105/7 "2025-09-30T17:07:28Z")

</div>

It filters out None values, so if `json.get(‘tagPath’)` returns None it’s not in the final list that gets joined via `’/’`

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 30, 2025, 5:09pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105/8 "2025-09-30T17:09:46Z")

</div>

Ah, okay, I've never used it so I misunderstood it to mean "don't filter anything"...

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 30, 2025, 5:12pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105/9 "2025-09-30T17:12:47Z")

</div>

It’s a special case that was included presumably because its such a common operation. It removes all fasly values , 0, None, ‘‘, False, {} etc

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 30, 2025, 5:15pm UTC](https://forum.inductiveautomation.com/t/help-cleaning-code/111105/10 "2025-09-30T17:15:15Z")

</div>

This is why I keep browsing these forums. Now that I know I'll likely ending up using it myself at some point...
