AutoTools Adding Values to an existing json file

Discussion in 'AutoApps' started by Glenn Delmotte, Jul 27, 2017.

  1. Glenn Delmotte

    Glenn Delmotte New Member

    Joined:
    Feb 22, 2015
    Messages:
    13
    Likes Received:
    1
    Hello,

    I have been trying to figure out how I can add values to an existing JSON file.
    This is my JSON File
    Code (Text):
    {
        "Tasks": {
            "Current": [
                {
                    "name": "Bla",
                    "day": 4,
                    "date": "26/07/2017",
               
                },
                {
                    "name": "Test",
                    "day": 4,
                    "date": "27/07/2017",
               
                }
               
            ],
            "Complete": [
                {
                    "name": "Testing",
                    "day": 1,
                    "date": "23/07/2017",
                    "delay": 0
               
                },
                {
                    "name": "Testing 2",
                    "day": 2,
                    "date": "24/07/2017",
                    "delay": 0
               
                },
                {
                    "name": "Testing 3",
                    "day": 3,
                    "date": "25/07/2017",
                    "delay": 0
               
                }
            ],
            "Incomplete": [
                {
                    "name": "Task"
                   
                },
                {
                    "name": "Another Task"
                },
                {
                    "name": "One more task"
                }
            ]
        }
    }
    I wanted to create a task with wich shows a dialog box where I can add anoter tasks tot the "Incomplete " list using JSON Write. However it just creates an entirely new "Incomplete" block instead of adding to the existing one.

    Any tips on how to do this?
     
  2. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,479
    Likes Received:
    806
    Here's how you can do this:

    Code (Text):
    Test Json (540)
        A1: Variable Set [ Name:%json To:{
        "Tasks": {
            "Current": [
                {
                    "name": "Bla",
                    "day": 4,
                    "date": "26/07/2017"
                },
                {
                    "name": "Test",
                    "day": 4,
                    "date": "27/07/2017"
                }
            ],
            "Complete": [
                {
                    "name": "Testing",
                    "day": 1,
                    "date": "23/07/2017",
                    "delay": 0
                },
                {
                    "name": "Testing 2",
                    "day": 2,
                    "date": "24/07/2017",
                    "delay": 0
                },
                {
                    "name": "Testing 3",
                    "day": 3,
                    "date": "25/07/2017",
                    "delay": 0
                }
            ],
            "Incomplete": [
                {
                    "name": "Task"
                },
                {
                    "name": "Another Task"
                },
                {
                    "name": "One more task"
                }
            ]
        }
    } Recurse Variables:Off Do Maths:Off Append:Off ]
        A2: AutoTools Json Read [ Configuration:Simple Mode: true
    Json: %json
    Fields: Incomplete(),Current(),Complete()
    Separator: , Timeout (Seconds):60 ]
        A3: AutoTools Json Write [ Configuration:Separator: ,
    Json Keys: name
    Json Values: Super Task
    Arrays Separator: | Timeout (Seconds):60 ]
        A4: Array Push [ Variable Array:%incomplete Position:9999 Value:%newtask Fill Spaces:Off ]
        A5: AutoTools Json Write [ Configuration:Separator: ####
    Json Keys: Incomplete####Current####Complete
    Json Values: [%incomplete()]####[%current()]####[%complete()]
    Prettify: true
    Arrays Separator: | Timeout (Seconds):60 ]
        A6: AutoTools Json Write [ Configuration:Separator: ####
    Json Keys: Tasks
    Json Values: %newtasks
    Prettify: true
    Arrays Separator: | Timeout (Seconds):60 ]
        A7: Flash [ Text:%final Long:Off ]
     
    I realize it's quite a bit of work, but it's the best way I found to support all possible situations. Hope this helps!
     
  3. Glenn Delmotte

    Glenn Delmotte New Member

    Joined:
    Feb 22, 2015
    Messages:
    13
    Likes Received:
    1
    Thank you!
     

Share This Page