Tinderbox JSON demo

This is my first try at using Tinderbox to process JSON data, so I thought I’d post my success in case any other beginner-users needed an example.

I use the app “Timing” to track my daily activities on my MacBook Pro, and the app produces a JSON file with records that show times, durations, programs used, and projects worked-on.

I wanted to incorporate this JSON data in my daily Tinderbox journal file, and so I worked-up a demo that shows how I figure out how to read a JSON file and create individual notes. The file is attached with some demo data.

I want to improve this by creating a Tinderbox dashboard and summarizing the duration and project data, but that’s the next step I’ll work on.

Timing JSON demo.tbx (235.3 KB)

2 Likes

Thanks for sharing this. When opening the above TBX, the key parts I observe are:

  • the JSON source being used is the $Text of note “Timing Input” at the top of the outline.
  • the code reading and generating output from the JSON is stamp note “Process JSON simple”—helpfully opened as a separate window in the TBX supplied.
  • the result of the stamp is the container “Daily JSON Tracking” and contents

Replicating those steps, I only get part of the way, so I wonder if a bit of code is missing. I renamed your example output container (so as not to alter/overwrite it) and got this output:

Issues:

  • The new child notes aren’t getting the correct prototype set (as would be expected from the code)
  • Of the attributes being set, only $duration is being populated

Odd side observation. Although the user attribute duration ($duration) exists in the document, the action code syntax colouring in the stamp shows the attribute in black as if not defined. Strange.

Regardless of issues above, thanks for sharing such a useful practical example. :slight_smile:

I think the naming is fixed by this,

image

but the code only seems to save the last json grouping. I am unsure how to fix the code so that each json grouping creates a note.

Regarding $duration not being highlighted, I have seen this before in which the attribute is lower case instead of upper case. $UpperCase gets highlighted, but $lowerCase does not.

HTH

Nice example for the community.
Tom

Thanks @TomD, and also @mwra for the great comments and suggestions.

I continued to work through the process of reading and processing JSON data, and building notes and containers to utilize the information.

This Tinderbox file shows where I am now; it correctly reads the JSON entries and builds a container for each day-group and populates the note attributes. I also use the sum function in the containers to add-up the JSON duration intervals.

This file also shows how I’ve learned (from this Forum and the weekly Meetups) how to organize a Tinderbox file for clarity and use by “future me.”

Very satisfying!

Learning to process JSON.tbx (465.6 KB)

Further comments & suggestions welcome, of course …

1 Like

Nice work Paul!

For those that use theBrain and Tana, I think, the most complete export from these apps is JSON. Concepts from this file could be used to bring data into Tinderbox via JSON

Tom

Thanks @TomD … you uncovered my secret plot to import JSON data from my 20-year Brain file. Until now, impenetrable

2 Likes

I have stayed away for that same reason. I counted 13 separate json files in my theBrain compressed export. Instead, I decided to get what I could from .txt export and RUN. I remember looking at their forums and for years people have been asking for simpler export options such as csv, tsv and it seems as they have chosen to not listen. I think I started with v8, they are now at v14. Same export options as before. No love.

Please keep me/us updated on your progress. I am certain other active theBrain users that also use Tinderbox would love to go along for the journey. Up to now, your description as an impenetrable black box is correct, at least for me.

JSON has always been hard for me to use, you have begun to open my eyes to begin exploring its use and understanding with Tinderbox. On another note, I thought the JSON stream operators were designed to simplify use. I am not sure if you have tried them for this use case.

Tom

1 Like

Thanks for sharing again. I’m sure i’m not the only one to find seeing the evolution of the project useful in itself.

Now that stamps are stored as note, having a lot of code in a stamp isn’t the issue it was as the stamp note can be opens a stand-alone window allowing better sight at the code. You can also call a stamp via code(using stamp()).

Conversely, not Tinderbox has functions, you could consider putting the code in a function and calling the function either via a stamp, or OnAdd, etc. But you don’t need to do this—if the code works it works.

An example of something that could be further abstracted, if only for a shorter stamp is that in the note-creating part, both branches of the ‘if()’ statement are the same from create(... through to the end). You could put that in a function. So, assume you did that in a function called fCreateUsageNote() , e.g.:

function `fCreateUsageNote(iPath:string){
 ...etc

Then your conditional becomes:

   if(vActivity!=oldActivity)
     {
      create(vPath+"/"+vActivity); 
      $Prototype(vPath+"/"+vActivity)="pCategory";
      vName=vPath+"/"+vActivity+"/"+vProject;
      Log("vName="+vName);
      fCreateUsageNote(vName);
      } 
     else 
       { 
        fCreateUsageNote(vName);
       }

But, this is more something you might choose to do—if only a a learning exercise—than need to do fro effective functioning of the code.

Nice work on the logging aspect. As you’ve doubtless found, a little while spent logging can help tack down hard to guess unexpected results in the middle of a script.

Thanks again :slight_smile:

1 Like