How to create / append bulk tooltips via script with json export?

What is the best way to append tooltips onto all tags in a json tag export? I have seen it done before. I just dont know how to make it happen myself.
What i have seen is a python script(outside of ignition) reads the json export file, parses it out and and adds the tooltip line to each tag (tooltip includes "TagName: "(tag name) “
” (opc itempath)). Then it creates a new copy of the updated json file.
I really dont know how to put it all together.

Could i get some help coming up with that script?

related info:
[default]PEM1/DataBlocks/HMI_Status/G000/Current

{
“valueSource”: “opc”,
“opcItemPath”: “ns\u003d1;s\u003dPEM1.DataBlocks.HMI_Status.G090.Current”,
“dataType”: “Float4”,
“historyProvider”: “CGTDB”,
“historicalDeadband”: 0.1,
“historicalDeadbandStyle”: “Discrete”,
“name”: “Current”,
“historyEnabled”: true,
“deadband”: 0.01,
“tagType”: “AtomicTag”,
“opcServer”: “TANI OPC UA SERVER”
}

Thanks

You could do it all in igntion, the only reason I do it outside is to have an executable.

Capture the clipboard
Convert json string in clipboard to python objects with system.util.jsonDecode
Manip lista/dicts
Comber back to json string with… Encode
Paste back to clipboard

I’ll post more details later on

Thanks.
And to clarify, im trying to append tooltips into the .json TAG EXPORT, then import them back in, not a window/view. (almost all of our applications are in vision)
Im not sure i follow. i get the decode and encode.

If you do have an executable would it be to much for me to ask for a copy?
Ever since IA got away from CSV tag exports its made manipulating tags very difficult.(i realize there is always a way with scripting but im a novice at python/scripting at best)

as we migrate more to Perspective soon it would come in handy too.

You can do it with jq (a downloadable command-line executable designed to manipulate JSON):
walk( if type == "object" and .valueSource == "opc" then .tooltip = "TagName: \(.name) \(.opcItemPath)" else . end)
https://jqplay.org/s/Pe6T7qNEFY

I mostly copied this snippet from here:

1 Like

Holy Moly! i had not heard of jq. That one line of code got me what i needed with a couple minor tweeks. Thats powerfull! When i saw this done with a .py script it was 30 lines of python i could not follow. One line i can almost follow is better than 30!
Great, another language i have to learn how to use and fail trying.
fyi. the website jqplay.org could only handle a 10 MB payload. one of my 12 folders of tags is about 20 MB. Hopfully the offline downloaded version has a higher / no size limit.

walk( if type == "object" and .valueSource == "opc" then .tooltip = "<html>TagName: \(.name) <br>Source: \(.opcItemPath)" else . end)

my end result (one of 500,000 tags):
{
“dataType”: “Float4”,
“deadband”: 0.01,
“historicalDeadband”: 0.1,
“historicalDeadbandStyle”: “Discrete”,
“historyEnabled”: true,
“historyProvider”: “CGTDB”,
“name”: “Current”,
“opcItemPath”: “ns=1;s=PEM1.DataBlocks.HMI_Status.G090.Current”,
“opcServer”: “TANI OPC UA SERVER”,
“tagType”: “AtomicTag”,
“valueSource”: “opc”,
"tooltip": "TagName: Current
Source: ns=1;s=PEM1.DataBlocks.HMI_Status.G090.Current"

}

Thanks for the help!

2 Likes

Yeah, I’ll admit I’ve heard of jq but never really had an occasion to use it. When I saw it could do this task in one pretty-readable line, I was pretty impressed.
As far as I’m aware, the downloaded version will handle whatever you throw at it; the website version is likely limited for the sake of browser performance.

After scouring for over 8hr non stop i cannot find a way to use jq to take a file that is not online (using “curl” function) and read file on my computer and run the script against it. Im sure it exists i just cannot find the way/syntax! Assistance would be appreciated. I will keep looking. This tool will save me weeks of tag editing on 500,000+ tags

jq is meant to be used from the command line - you should be able to invoke it on a local file just fine; in fact that’s the way it’s supposed to be used.
For instance, if I have jq for Windows downloaded, I can run this in a command prompt or other terminal window:
jq-win64.exe 'walk( if type == "object" and .valueSource == "opc" then .tooltip = "<html>TagName: \(.name) <br>Source: \(.opcItemPath)" else . end)' path/to/tag.json > tags_with_tooltips.json
The > tags_with_tooltips.json is ‘capturing’ the output buffer of the command and writing it to a new file.

Your script looks good, however, i cannot get it to process. Below is your above script with my path and my error. I appologize for the back and forth, i was trying to avoid it but the payoff is so great to get this working. (jq does work i can read a json file - “d:\jq JSON filter_manipulation>jq --slurp . tagspem12.json”)

d:\jq JSON filter_manipulation>jq.exe ‘walk( if type == “object” and .valueSource == “opc” then .tooltip = “TagName: (.name)
Source: (.opcItemPath)” else . end)’ D:/jq JSON filter_manipulation/tagspem12.json > tags_with_tooltips.json
jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Windows cmd shell quoting issues?) at , line 1:
'walk(
jq: 1 compile error

Perhaps
d:\jq JSON filter_manipulation>jq.exe "walk( if type == \"object\" and .valueSource == \"opc\" then .tooltip = \"TagName: (.name) Source: (.opcItemPath)\" else . end)" D:/jq JSON filter_manipulation/tagspem12.json > tags_with_tooltips.json

Quoting of strings, special characters, etc is going to vary by shell, and Windows’ cmd prompt is notoriously pretty terrible. My command above was done in Git Bash in the ‘new’ Windows Terminal.

I got it! After your input and some playing it needed double quotes as well as command prompt did not like the full path input. So i reduced it to just the file name(in bold). I even tried without the underscore in the original folder name. it appears it did not like the “:” and/or the “/” in the file path either.

This worked in command prompt (maybe I should look into Git Bash):
d:\jq JSON filter manipulation>jq.exe “walk( if type == “object” and .valueSource == “opc” then .tooltip = “TagName: (.name) Source: (.opcItemPath)” else . end)” tagspem12.json > tags_with_tooltips.json

Thanks for the help.

2 Likes

it probably had to be a \ instead of /