Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
JSON.Parse
Parses JSON text and return reference number.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JSON | 6.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example |
---|---|---|
JSON | The JSON text to parse. | "[1,2,3]" |
Result
Returns reference number or error.
Description
Parses JSON text and return reference number.Please use JSON.Release later to free the json object.
You can pass the reference number to all MBS JSON functions instead of JSON text.
Examples
Parse an array:
# parse some json
$ref = MBS( "JSON.Parse"; "[1,2,3]" )
# query array size:
MBS( "JSON.GetArraySize"; $ref)
# free memory
MBS( "JSON.Release"; $ref)
Parse some JSON, display it formatted and release:
Set Variable [$json; Value:MBS( "JSON.Parse"; "{\"Hello\": \"World\"}" )]
Show Custom Dialog [$json; MBS("JSON.Format"; $json)]
Set Variable [$r; Value:MBS( "JSON.Release"; $json)]
Query IP via ipinfo.io:
Go to Layout [“Table”]
New Record/Request
#Start new session
Set Variable [$curl; Value:MBS("CURL.New")]
#Set URL to load (HTTP, HTTPS, FTP, FTPS, SFTP, etc.)
Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; "http://ipinfo.io")]
#RUN now
Set Variable [$result; Value:MBS("CURL.Perform"; $curl)]
#Check result
Set Field [Table::DebugLog; MBS("CURL.GetDebugMessages"; $curl)]
Set Field [Table::Result; MBS("CURL.GetDebugMessages"; $curl; "UTF8")]
If [$result = "OK"]
#Check HTTP error code
Set Variable [$response; Value:MBS("CURL.GetResponseCode"; $curl)]
If [$response = 200]
#Query values from JSON
Set Variable [$json; Value:MBS( "JSON.Parse"; Table::Result )]
Set Field [Table::IP; MBS("JSON.GetPathItem"; $json; "ip"; 1)]
Set Field [Table::Hostname; MBS("JSON.GetPathItem"; $json; "hostname"; 1)]
Set Field [Table::City; MBS("JSON.GetPathItem"; $json; "city"; 1)]
Set Field [Table::Region; MBS("JSON.GetPathItem"; $json; "region"; 1)]
Set Field [Table::Country; MBS("JSON.GetPathItem"; $json; "country"; 1)]
Set Field [Table::Location; MBS("JSON.GetPathItem"; $json; "loc"; 1)]
Set Field [Table::Company or Provider; MBS("JSON.GetPathItem"; $json; "org"; 1)]
Set Variable [$r; Value:MBS( "JSON.Release"; $json )]
End If
End If
#Cleanup
Set Variable [$result; Value:MBS("CURL.Release"; $curl)]
Commit Records/Requests [No dialog]
Work with huge JSON by parsing once:
Set Variable [ $path ; Value: "/Users/cs/Desktop/test.json" ]
# read all the text from disk
Set Variable [ $text ; Value: MBS( "Text.ReadTextFile"; $path; "UTF-8") ]
# now parse JSON
Set Variable [ $json ; Value: MBS("JSON.Parse"; $text) ]
# and do something with it
Set Variable [ $json ; Value: MBS("JSON.GetArraySize"; $json) ]
# when done, please free memory
Set Variable [ $r ; Value: MBS("JSON.Release"; $json) ]
See also
- CURL.GetDebugMessages
- CURL.GetResponseCode
- CURL.Release
- CURL.SetOptionURL
- JSON.AddBooleanToObject
- JSON.DeleteItemFromArray
- JSON.Format
- JSON.GetPathItem
- JSON.List
- JSON.Release
Release notes
- Version 11.2
- Changed JSON.Parse to be accept leading zeros on numbers.
Example Databases
- CURL/Email/IMAP Email List
- CURL/Email/IMAP Email
- CURL/WebServices/Query IP and Country
- JSON/JSON Benchmark
- Mac and iOS/Machine Learning/Core Image Detection
Blog Entries
- Data structures in MBS Plugin
- MBS FileMaker Plugin, version 11.2pr2
- With JSON in excellent form
- JSON with large integers
- Face detection via CoreImage in FileMaker
- MBS FileMaker Plugin 6.0 for OS X/Windows
- MBS FileMaker Plugin, version 6.0pr6
Created 5th January 2016, last changed 1st November 2023
