JSON, Level: Advanced, Version: FM 18 or later

FM18: JSON.InsertArrayElement

18 Sep 2022 – these custom functions have been upgraded – see JSON Custom Functions for FM 19.5, part 2 for details.

Disclaimer: the technique shown in this article is provided on an as-is basis. Use with appropriate caution and at your own risk.

Demo file: JSON-Array-Custom-Functions.zip (requires FM 18 or later)

201-08-23-animated

Have you ever noticed that FileMaker does not provide a JSON function to insert a new element into an existing array? For example, given this array (and bearing in mind that JSON uses a zero-based index)…

[ “A” , “B” , “C” , “D” ]

…JSONSetElement ( array ; 2 ; “XXX” ) will transform it to…

[ “A” , “B” , “XXX” , “D” ]

… but we have no native JSON function to “push” a new element into position 2 so that existing elements slide one position rightward to accommodate, like so:

[ “A” , “B” , “XXX” , “C” , “D” ]

Continue reading “FM18: JSON.InsertArrayElement”

JSON, Level: Advanced, Version: FM 18 or later

FM18: JSON.UpdateArrayElement

18 Sep 2022 – these custom functions have been upgraded – see JSON Custom Functions for FM 19.5, part 2 for details.

Disclaimer: the technique shown in this article is an attempt to work around an annoyance that can crop up when using FileMaker’s native JSONSetElement function, and is provided on an as-is basis. Use with appropriate caution and at your own risk.

Acknowledgement: I owe a debt of gratitude to Paul Jansen for many illuminating JSON-related discussions over the last year or so. Thank you Paul.

Introduction

Today we’re going to look at a custom function, JSON.UpdateArrayElement, written to circumvent a problem you may encounter when using JSONSetElement. (Note: see Thinking About JSON, part 1 and part 2 if you need a basic FM/JSON overview or refresher.)

Demo file: JSON-UpdateArrayElement-v3.zip (requires FM 18 or later)

2019-08-13_16-02-58.png

Why did I write a custom function to do what JSONSetElement apparently already does? Because under certain circumstances JSONSetElement does not work the way I believe it should. We’ll get to the custom function in a minute, but first there are a couple issues we need to examine. Continue reading “FM18: JSON.UpdateArrayElement”

JSON, Level: Advanced, Version: FM 16 or later

Magic Portals

Today we’re going to look at a design pattern I’ve recently been using to accommodate a client request. The request is to be able to view and edit a parent, all related children, and all related grandchildren via a single “flattened” interface.

2019-04-24_16-22-61

Demo file: magic-portals.zip (requires FM 16 or later) Continue reading “Magic Portals”

JSON, Level: Intermediate, Version: FM 16 or later

Creating and Using Invisible Window IDs

Editor’s note: I first became aware of Paul Jansen when I licensed his FMTools in the late 1990s, and I finally had the pleasure of meeting him last June at dotFMP after 20 years of online and voice communication. It’s an honor and a privilege to welcome him to FileMaker Hacks as a guest author.

FileMaker is pretty flexible. As developers we are given options as to how to reference things; fields, scripts and layouts can be referenced by name or number/id. Whilst we know that referencing things by name is more fragile, it is still a very useful capability to have, but it is definitely more robust to reference by ID…

Windows are a bit of an odd one out; we can only reference them by name.

As windows are probably the most likely things to have their names changed during normal day to day usage of a FileMaker Database it would be really useful if we could keep track of them by an ID independent of the displayed window title. Another benefit of having access to an ID to identify a window is that we then have to option to very easily store and access window specific variables. Kevin has made use of window specific variables based upon the window name in several articles and I suggest that access to a numeric ID that was independent of the window title would be an improvement. Continue reading “Creating and Using Invisible Window IDs”

JSON, Level: Intermediate, Version: FM 16 or later, Virtual List

Faux Subsummaries via JSON + Virtual List

Today we’re going to take another look at a challenge we discussed last time (in Conditional Summary Report Header)… namely how to cajole FileMaker into displaying a subsummary, or a reasonable facsimile thereof, at the top of a report page when items in the group begin on an earlier page.

2018-10-15_09-45-51

Demo file: Faux Subsummaries via JSON + Virtual List

2018-10-15_09-54-56.png Continue reading “Faux Subsummaries via JSON + Virtual List”

JSON, Level: Intermediate

Thinking About JSON, part 3

This article is part of a series. See also…
•  Thinking About JSON, part 1
•  Thinking About JSON, part 2
•  Thinking About JSON, part 4

This a quick followup to last month’s part 2, because today I want to to dig a little deeper into JSONSetElement and take a closer look at the first argument:

2018-08-09_090804

As I wrote last time…

Part of what makes JSONSetElement so powerful is that it can be used both to create new entries, and to update existing entries. Specify a valid address, and it will either create the entry if it doesn’t already exist, or update it if it does.

Let’s talk about the update aspect first, because it’s extremely straight forward. If you have existing JSON in a variable, for example $$simpleJSON, you can update it (i.e., add new elements or change existing elements) like so:

    • JSONSetElement ( $$simpleJSON ; etc )

In other words, you use your existing JSON as the first argument.

But when it comes to creating new JSON, there are three possible first arguments to consider.

    • JSONSetElement ( “{}” ; etc )
      …instructing FileMaker to create a JSON object
    • JSONSetElement ( “[]” ; etc )
      …instructing FileMaker to create a JSON array
    • JSONSetElement ( “” ; etc )
      …trusting FileMaker to figure out which structure to create

At the risk of stating the obvious, in the first two cases we are being explicit, but in the third case we are not. (Note: If you’re unclear on the distinction between objects and arrays, this was covered in great detail in part 1.)

Continue reading “Thinking About JSON, part 3”

JSON, Level: Intermediate, Version: FM 16 or later

Thinking About JSON, part 2

This article is part of a series. See also…
•  Thinking About JSON, part 1
•  Thinking About JSON, part 3
•  Thinking About JSON, part 4

This is a follow up to Thinking About JSON, part 1. Last time we were primarily concerned with learning about JSON paths and structures, and reading JSON. This time around we’re going to look at creating and manipulating JSON.

Demo file: winery-json.zip

(If the above screen shot looks familiar you have a good memory, because today’s demo is based on the one that accompanied this article: Summary List Fields in FM 13.)

To briefly recap, JSON is built on two structures…

  • Objects: surrounded by {} and consisting of comma-separated key:value pairs
    Simple example:  { “product” : “FileMaker Pro” , “version” : 17 }
  • Arrays: surrounded by [] and consisting of comma-separated values
    Simple example:  [ 2 , 4 , 6 ]

…and where things get interesting is that the “values” in either of the above structures can themselves be JSON (i.e., an object or an array). This defining feature of JSON, whereby a JSON structure can, and frequently does, contain embedded smaller JSON structures, was explored in detail in part 1, and we will see some examples of this today as well. Continue reading “Thinking About JSON, part 2”

JSON, Level: Advanced, Version: FM 16 or later, Virtual List

Virtual List Reporting with JSON Arrays

Acknowledgment: As always a huge thank you to Bruce Robertson, for inventing virtual list, and for many other contributions to the FM community over the years.

Introduction

As a follow up to my recent “Virtual List on Steroids” presentations at DIG-FM and dotFMP, today I want to take a fresh look at using JSON arrays in conjunction with Virtual List Reporting.

JSON Array

JSON arrays + Virtual List are a natural fit, but, as we shall see, small changes in methodology can make a huge difference in terms of performance, and the approaches we’re going to explore today are the result of a lot of trial and error, and incorporate feedback and suggestions from Dave Graham, Paul Jansen and Perren Smith.

What follows will assume the reader is somewhat familiar with the basic ideas behind Virtual List. If you aren’t familiar, or need a refresher, check out Virtual List Simplified. We’ll get to the demos in just a minute, but first, a review of some of the benefits of using virtual list.

  • Flexible framework accommodates complex reporting challenges
  • Fast performance
  • No need to tamper with schema in your data tables or on the relationships graph
  • Unlike traditional FM reports, you can easily combine data from unrelated tables
  • Under certain circumstances, virtual list reports (VLRs) can be much faster to develop than traditional FM reports
  • 100% multi-user safe and friendly

Overview

Here’s the main idea in a nutshell:

2018-06-24_182509.png Continue reading “Virtual List Reporting with JSON Arrays”

JSON, Level: Intermediate, Version: FM 16 or later, Virtual List

Virtual List on Steroids, part 2

[10 June 2018: includes updated material from my recent dotFMP presentation.]

[30 May 2018: check out my reassessment of the Fast Summary technique here.]

2018-05-09_19-04-17.png

Here are files that were demoed or referred to during my “Virtual List on Steroids” DIG-FM presentation on Thursday, May 10th, 2018 (VLR = “virtual list reporting). Continue reading “Virtual List on Steroids, part 2”

JSON, Level: Intermediate, Version: FM 16 or later

Thinking About JSON, part 1

This article is part of a series. See also…
•  Thinking About JSON, part 2
•  Thinking About JSON, part 3
•  Thinking About JSON, part 4

I’ve been working on a couple large JSON projects over the last few months, and with the one year anniversary of FileMaker having built-in JSON capabilities just around the corner, this seems an opportune moment to share some reflections and opinions (some of which may contradict JSON-related opinions I have expressed previously).

Demo file: json-sandbox.zip

This article is intended to be a structured introduction to JSON in FileMaker. There are some other good FM/JSON resources out there, and I recommend these in particular:

At any rate, if you’re not yet completely comfortable with JSON perhaps some of the following will be helpful, or failing that, amusing (intentionally or otherwise). Continue reading “Thinking About JSON, part 1”