Skip to content

selwynjackson/Gitjson

Repository files navigation

NodeRED json file converter

json files generated by NodeRED contain long lines with '\n' sequences embedded.
This makes it difficult to compare versions using Git.

The Gitjson converts all "\n" text sequences to '\n>>\t\t' so that it is easy to view differences in files.
The same utility can unconvert the files back to the original format.

When running the utility without arguments, the use of the utility is shown:

Gitjson - Version 1.0 - Convert NodeRED json for use by Git and vica versa
Text '\n' is converted to 'LF >> tab tab'
Use: Gitjson <sourcefile.json> <destinationfile>
     Gitjson <sourcefile.json> - to convert to sourcefile.gitjson
     Gitjson <sourcefile.gitjson> - to unconvert to sourcefile.json
     Gitjson <flows*.json> to convert to <project><label.gitjson> - where label is extracted from json file
     Gitjson /p <project> - to set project directory
     Gitjson /p - to clear project directory
Project is currently set to 'D:\GitWork\NodeRED\'

The project option is useful for moving the json file from the downloads directory directly into the project directory, with the flows*.json filename converted to the first label in the json file (usually the title of the first flow).

The utility must be stored in a directory in the path, or the path must be updated to include this utility. Then the .json file should be opened with the utility, and the association should be be set as always.

For example, the json file:

    {
        "id": "409204e812490f3e",
        "type": "function",
        "z": "037f60a1d649c5d0",
        "g": "e9b8350557492c20",
        "name": "add",
        "func": "var val1 = parseFloat(flow.get(\"val1\") || \"0\");\nvar val2 = parseFloat(flow.get(\"val2\") || \"0\");\nmsg.payload = val1 + val2;\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 1140,
        "wires": [
            [
                "00778b9e2763b416",
                "95548b5957bf4a93"
            ]
        ]
    },

is converted to to a gitjson file:

    {
        "id": "409204e812490f3e",
        "type": "function",
        "z": "037f60a1d649c5d0",
        "g": "e9b8350557492c20",
        "name": "add",
        "func": "var val1 = parseFloat(flow.get(\"val1\") || \"0\");
>>		var val2 = parseFloat(flow.get(\"val2\") || \"0\");
>>		msg.payload = val1 + val2;
>>		return msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 1140,
        "wires": [
            [
                "00778b9e2763b416",
                "95548b5957bf4a93"
            ]
        ]
    },

About

json files are converted to Gitjson files that are easily readable and can be compared with Git utilities.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors