All Projects → jbante → FM-JSON-Types

jbante / FM-JSON-Types

Licence: other
FileMaker Data Types in JSON

Projects that are alternatives of or similar to FM-JSON-Types

Timestamp
⏰ A better macOS menu bar clock.
Stars: ✭ 296 (+2014.29%)
Mutual labels:  time, date, timestamp
Tinydate
A tiny (349B) reusable date formatter. Extremely fast!
Stars: ✭ 990 (+6971.43%)
Mutual labels:  time, date, timestamp
Time Stamp
Get a formatted timestamp. Used in gulp, assemble, generate, and many others.
Stars: ✭ 104 (+642.86%)
Mutual labels:  time, date, timestamp
SonataTimelineBundle
[Abandoned] Integrates SpyTimelineBundle into Sonata
Stars: ✭ 24 (+71.43%)
Mutual labels:  time, date
Travel
Framework agnostic PHP package to control the time.
Stars: ✭ 251 (+1692.86%)
Mutual labels:  time, date
nativescript-datetimepicker
Plugin with date and time picking fields
Stars: ✭ 26 (+85.71%)
Mutual labels:  time, date
Dpicker
A framework-agnostic minimal date picker
Stars: ✭ 187 (+1235.71%)
Mutual labels:  time, date
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (+135.71%)
Mutual labels:  time, date
iso8601
A fast ISO8601 date parser for Go
Stars: ✭ 122 (+771.43%)
Mutual labels:  time, date
date-extractor
Extract dates from text
Stars: ✭ 58 (+314.29%)
Mutual labels:  time, date
temps-lite
A smart, good-looking little app which tries to speak your language the way you are used to.
Stars: ✭ 40 (+185.71%)
Mutual labels:  time, date
Jiffy
Jiffy is a Flutter (Android, IOS and Web) date time package inspired by momentjs for parsing, manipulating, querying and formatting dates
Stars: ✭ 238 (+1600%)
Mutual labels:  time, date
Sonataintlbundle
Symfony SonataIntlBundle
Stars: ✭ 212 (+1414.29%)
Mutual labels:  time, date
ptera
Ptera is DateTime library for Deno
Stars: ✭ 62 (+342.86%)
Mutual labels:  time, date
React Native Modal Datetime Picker
A React-Native datetime-picker for Android and iOS
Stars: ✭ 2,412 (+17128.57%)
Mutual labels:  time, date
jodaTime
Format and Parse date and time with joda layout
Stars: ✭ 67 (+378.57%)
Mutual labels:  time, date
timelite
String date and time utilities 🕙
Stars: ✭ 17 (+21.43%)
Mutual labels:  time, date
time machine
A date and time API for Dart
Stars: ✭ 120 (+757.14%)
Mutual labels:  time, date
TimesDates.jl
Nanosecond resolution for Time and Date, TimeZones
Stars: ✭ 28 (+100%)
Mutual labels:  time, date
Eztime
ezTime — pronounced "Easy Time" — is a very easy to use Arduino time and date library that provides NTP network time lookups, extensive timezone support, formatted time and date strings, user events, millisecond precision and more.
Stars: ✭ 173 (+1135.71%)
Mutual labels:  time, timestamp

FileMaker JSON Type Handling

FileMaker 16 introduced a collection of built-in functions for manipulating data serialized as JSON. This makes it easier for FileMaker applications to interact with many web services. This will also make JSON the de facto standard format for scripts within FileMaker to pass parameters and results to each other, improving code sharing within the FileMaker community.

JSON does not have a broad palette of scalar data types to choose from: text, number, boolean, and null. On top of that, incoming JSON data may inappropriately format boolean or numeric data as text. Sending and receiving data with correct types requires more logic on top of the new JSON functions.

This module uses ISO 8601 format for dates, times, and timestamps. This is the most popular method for representing such data used by web services, so this module is also useful for integrating web services with FileMaker applications.

This module supports two approaches for translating between FileMaker data types and JSON data:

  1. Custom functions - This approach is convenient to read and write. However, copying logic using the custom functions from one file to another is more complicated, since the custom functions must also be copied, and they must be copied before any dependent logic.
  2. Scripts - This approach is convenient to copy and paste between FileMaker files as part of a module script folder. However, code using these scripts for data translation is more cumbersome than using the custom functions.

Installation

  1. Import all the custom functions from the FileMaker file into your application. You can skip this step if you only want to use scripts to translate typed data between FileMaker and JSON.
  2. Import the "Modules" / "FM-JSON Types" script folder and all its contents from the FileMaker file into your application.

How to use the custom functions

Set a number:
JSONSetElement ( "{}" ; "numberKey" ; 1.23e+4 ; JSONNumber )
= {"numberKey":1.23e+4}
Get a number:
JSONGetNumber ( $json ; "numberKey" )
= 1.23e+4

Since JSON supports number-type data, no function is necessary when serializing to JSON. The JSONGetElement function in FileMaker 16.0.2 and later will automatically return number-type data if the element is a JSON number. However, the JSONGetNumber custom function may still be useful for handling data from sources that inappropriately format numeric data as JSON strings.

Set a boolean:
JSONSetElement ( "{}" ; "booleanKey" ; False ; JSONBoolean )
= {"booleanKey":false}
Get a boolean:
JSONGetBoolean ( $json ; "booleanKey" )
= 0

Since JSON supports boolean-type data, no function is necessary when serializing to JSON. The JSONGetElement function in FileMaker 16.0.2 and later will automatically return boolean-type data if the element is a JSON boolean. (Note that FileMaker represents boolean values as numbers, 0 for false and 1 for true.) However, the JSONGetBoolean custom function may still be useful for handling data from sources that inappropriately format boolean data as JSON strings.

Set a date:
JSONSetElement ( "{}" ; "dateKey" ; ISOFromDate ( Date ( 5 ; 9 ; 2017 ) ) ; JSONString )
= {"dateKey":"2017-05-09"}
Get a date:
JSONGetDateFromISO ( $json ; "dateKey" )
= 9 May 2017

Dates are formatted according to ISO 8601 and serialized as JSONStrings.

Set a time:
JSONSetElement ( "{}" ; "timeKey" ; ISOFromTime ( Time ( 18 ; 34 ; 56.7 ) ) ; JSONString )
= {"timeKey":"18:34:56,7"}
Get a time:
JSONGetTimeFromISO ( $json ; "timeKey" )
= 6:34:56.7 pm

Times are formatted according to ISO 8601 and serialized as JSONStrings. ISO 8601 supports time zones, but FileMaker times do not. These functions will ignore time zone information from other sources.

Set a timestamp:
JSONSetElement ( "{}" ; "timestampKey" ; ISOFromTimestamp ( $timestamp ) ; JSONString )
= {"timestampKey":"2017-05-09T12:34:56,7"}
Get a timestamp:
JSONGetTimestampFromISO ( $json ; "timestampKey" )
= 9 May 2017, 6:34:56.7 pm

Timestamps are formatted according to ISO 8601 and serialized as JSONStrings. ISO 8601 supports time zones, but FileMaker timestamps do not. These functions will ignore time zone information from other sources.

Set a container:
JSONSetElement ( "{}" ; "containerKey" ; JSONContainerObject ( $container ) ; JSONObject )
= {"containerKey":{"base64":"iVBOR...","fileName":"image.png"}}
Get a container:
JSONGetContainer ( $json ; "containerKey" )

Containers are serialized as JSONObjects with sub-values for the file name and the base 64-encoded binary data.

How to use the scripts

Set a number:
Perform Script [ "Your Script" ; Parameter: JSONSetElement ( "{}" ; "numberKey" ; 1.23e+4 ; JSONNumber ) ]
Get a number:
Set Variable [ $number ; Value: GetAsNumber ( JSONGetElement ( Get ( ScriptResult ) ; "numberKey" ) ) ]

Since FileMaker has a built-in GetAsNumber function, there is no value in using a separate script to interpret number data from JSON. The JSONGetElement function in FileMaker 16.0.2 and later will automatically return number-type data if the element is a JSON number. However, explicitly casting the value as a number may still be useful for handling data from sources that inappropriately format numeric data as JSON strings.

Set a boolean:
Perform Script [ "Your Script" ; Parameter: JSONSetElement ( "{}" ; "booleanKey" ; False ; JSONBoolean ) ]
Get a boolean:
Set Variable [ $boolean ; Value: GetAsBoolean ( JSONGetElement ( Get ( ScriptResult ) ; "booleanKey" ) ) ]

Since FileMaker has a built-in GetAsBoolean function, there is no value in using a separate script to interpret boolean data from JSON. The JSONGetElement function in FileMaker 16.0.2 and later will automatically return boolean-type data if the element is a JSON boolean. (Note that FileMaker represents boolean values as numbers, 0 for false and 1 for true.) However, explicitly casting the value as a boolean may still be useful for handling data from sources that inappropriately format boolean data as JSON strings.

Set a date:
Perform Script [ "Convert to ISO 8601 from Date" ; Parameter: Date ( 5 ; 9 ; 2017 ) ]
Set Variable [ $json ; Value: JSONSetElement ( "{}" ; "dateKey" ; Get ( ScriptResult ) ; JSONString ) ]
Get a date:
Perform Script [ "Convert to Date from ISO 8601" ; Parameter: JSONGetElement ( $json ; "dateKey" ) ]
Set Variable [ $date ; Value: Get ( ScriptResult ) ]

Dates are formatted according to ISO 8601 and serialized as JSONStrings.

Set a time:
Perform Script [ "Convert to ISO 8601 from Time" ; Parameter: Time ( 18 ; 34 ; 56.7 ) ]
Set Variable [ $json ; Value: JSONSetElement ( "{}" ; "timeKey" ; Get ( ScriptResult ) ; JSONString ) ]
Get a time:
Perform Script [ "Convert to Time from ISO 8601" ; Parameter: JSONGetElement ( $json ; "timeKey" ) ]
Set Variable [ $time ; Value: Get ( ScriptResult ) ]

Times are formatted according to ISO 8601 and serialized as JSONStrings. ISO 8601 supports time zones, but FileMaker times do not. These scripts will ignore time zone information from other sources.

Set a timestamp:
Perform Script [ "Convert to ISO 8601 from Timestamp" ; Parameter: $timestamp ]
Set Variable [ $json ; Value: JSONSetElement ( "{}" ; "timestampKey" ; Get ( ScriptResult ) ; JSONString )
Get a timestamp:
Perform Script [ "Convert to Timestamp from ISO 8601" ; Parameter: JSONGetElement ( $json ; "timestampKey" ) ]
Set Variable [ $timestamp ; Value: Get ( ScriptResult ) ]

Timestamps are formatted according to ISO 8601 and serialized as JSONStrings. ISO 8601 supports time zones, but FileMaker timestamps do not. These scripts will ignore time zone information from other sources.

Set a container:
Perform Script [ "Convert to JSONObject from Container" ; Parameter: $container ]
Set Variable [ $json ; Value: JSONSetElement ( "{}" ; "containerKey" ; Get ( ScriptResult ) ; JSONObject ) ]
Get a container:
Perform Script [ "Convert to Container from JSONObject" ; Parameter: JSONGetElement ( $json ; "containerKey" ) ]
Set Variable [ $container ; Value: Get ( ScriptResult ) ]

Containers are serialized as JSONObjects with sub-values for the file name and the base 64-encoded binary data.

License

Anyone may do anything with this software for any purpose. There is no warranty.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].