monkeydom / ObjectiveTOML

ObjectiveTOML is a simple Objective-C Library to read and write TOML files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


ObjectiveTOML is a clean and nice Objective-C API to read and write TOML files. It is utilizing toml11 and therefore on par with its TOML compliance. At time of writing this is TOML 1.0.0

The main target is a small command line utility tomlutil to convert between TOML, JSON and the xml and binary plist format on macOS.

The API is aligned with NSJSONSerialization:

#import "LMPTOMLSerialization.h"

NSData *inputData = [NSData dataWithContentsOfURL:fileURL];
NSDictionary <NSString *, id>* tomlObject = 
  [LMPTOMLSerialization TOMLObjectWithData:inputData error:&error];
// now tomlObject holds the contents of the TOML file. 

The tomlutil has nice parsing error reporting (if you only want this, you can use the -lint option:

$> ./tomlutil -lint toml-examples/wrong.toml 
🚫 Input TOML could not be parsed
[error] toml::parse_key_value_pair: invalid format for key
 --> toml-examples/wrong.toml
 14 | asdfpoin1!@ j= ;alskjfasdf
    |          ^--- invalid character in key
Hint: Did you forget '.' to separate dotted-key?
Hint: Allowed characters for bare key are [0-9a-zA-Z_-]. 

Current usage output:

tomlutil v2.0.0 (toml11 v3.7.1)

Usage: tomlutil [-f json|xml1|binary1|toml] file [outputfile]

A file of '-' reads from stdin. Can read json, plists and toml. Output defaults to stdout.
-f format   Output format. One of json, xml1, binary1, toml. Defaults to toml.
-lint       Just lint with toml11, no output.

Simple conversion of the Mojave plist to TOML:

$> ./tomlutil /System/Applications/ 
SBAppUsesLocalNotifications = true
DTSDKBuild = "22D40"
UILaunchStoryboardName = "LaunchScreen"
CFBundleHelpBookName = ""
NSSupportsSuddenTermination = true
DTPlatformVersion = "13.2"
UIViewGroupOpacity = false
CFBundleDisplayName = "News"
CFBundleName = "News"
HPDHelpProjectIdentifier = "news"
UIDeviceFamily = [6]
CFBundlePackageType = "APPL"
UIRequiredDeviceCapabilities = ["armv7"]
CFBundleSignature = "????"
UIMenuBarItemTitleQuit = "Quit News"
CFBundleVersion = "3270.0.1"
LSSupportedRegions = ["US","GB","AU","CA"]
NSLocationDefaultAccuracyReduced = true
UIMenuBarItemTitleHelp = "News Help"
NSLocationUsageDescription = """
Get top local news and weather, and locally relevant search results an\
d ads.\
UIMenuBarItemTitleAbout = "About News"
UIMenuBarItemTitleHide = "Hide News"
NSCalendarsUsageDescription = "This will let you add events from News to your calendar."
CFBundleSupportedPlatforms = ["MacOSX"]
NSLocationWhenInUseUsageDescription = """
Get top local news and weather, and locally relevant search r\
esults and ads.\
CFBundleInfoDictionaryVersion = "6.0"
LSMinimumSystemVersion = "13.2"
CFBundleIdentifier = ""
NSHumanReadableCopyright = "Copyright © 2022 Apple Inc. All rights reserved."
NSPhotoLibraryAddUsageDescription = ""
UIWhitePointAdaptivityStyle = "UIWhitePointAdaptivityStyleReading"
NSContactsUsageDescription = ""
NSSupportsAutomaticTermination = true
CFBundleShortVersionString = "8.2.1"
CFBundleIconFile = "AppIcon"
CTIgnoreUserFonts = true
UIAppFonts = []
UIUserInterfaceStyle = "Automatic"
DTXcodeBuild = "14A6270d"
CFBundleExecutable = "News"
DTCompiler = ""
CFBundleIconName = "AppIcon"
UIStatusBarHidden = false
"UISupportedInterfaceOrientations~ipad" = [
BuildMachineOSBuild = "20A241133"
UIViewControllerBasedStatusBarAppearance = true
UIBackgroundModes = ["audio","fetch","remote-notification"]
NSAccentColorName = "NewsAccentColor"
UIViewEdgeAntialiasing = false
DTPlatformName = "macosx"
SBMatchingApplicationGenres = [
NSUserActivityTypes = [
UIApplicationShortcutWidget = ""
CFBundleDevelopmentRegion = "en"
UISupportedInterfaceOrientations = ["UIInterfaceOrientationPortrait"]
CFBundleHelpBookFolder = ""
BGTaskSchedulerPermittedIdentifiers = [""]
_LSSupportsRemoval = true
DTSDKName = "macosx13.2.internal"
DTPlatformBuild = "22D40"
NSPhotoLibraryUsageDescription = ""
DTXcode = "1400"
LSCounterpartIdentifiers = [""]

UIApplicationShortcutItemTitle = "ApplicationShortcutItemForYou"
UIApplicationShortcutItemIconFile = "ios_for_you_icon_large"
UIApplicationShortcutItemType = ""

UNSuppressUserAuthorizationPrompt = false

UIApplicationSupportsMultipleScenes = "1"


UISceneConfigurationName = "Default Configuration"
UISceneDelegateClassName = "NewsUI2.SceneDelegate"
UISceneClassName = "TeaUI.WindowScene"

CFBundleURLSchemes = ["applenews","applenewss"]
CFBundleURLName = ""
CFBundleTypeRole = "Editor"

Full header:

@interface LMPTOMLSerialization : NSObject

 Generate a Foundation Dictionary from TOML data.

 @param data NSData representing a TOML file
 @param error helpful information if the parsing fails
 @return NSDictionary representing the contents of the TOML file. Note that given dates will be represented as NSDateComponents, use +serializationObjectWtihTOMLObject: to convert those to RFC3339 strings that can be used in JSON or PropertyList serializations.
+ (NSDictionary <NSString *, id>*)TOMLObjectWithData:(NSData *)data error:(NSError **)error;

 Generates NSData representation of the TOMLObject. The representation is UTF8 and can be stored directly as a TOML file.
 Note that roundtripping is a lossy opreation, as all comments are stripped, the allowed number formats are reduced to canonical ones and doubles might lose or gain unwanted precision.
 @param tomlObject Foundation Object consisting of TOML serializable objects. In addition to plist objects this contains NSDateComponent objects with y-m-d filled, h-m-s-[nanoseconds] filled, all fields filled, or all fields + timezone filled.
 @param error helpful information if generation fails
 @return NSData representing the object.
+ (NSData *)dataWithTOMLObject:(NSDictionary<NSString *, id> *)tomlObject error:(NSError **)error;

 Takes a Dictionary representing a TOML file and translates the NSDateComponents into RFC339 strings to be able to be serialized in JSON or PropertyLists

 @param tomlObject foundation dictionary consisting of TOML serializable objects.
 @return NSDictionary containing property list serializable objects.
+ (NSDictionary<NSString *, id> *)serializableObjectWithTOMLObject:(NSDictionary<NSString *, id> *)tomlObject;



  • v2.0.0

  • v1.1.0

    • Updated to cpptoml v0.1.1
    • Added more arguments, help and error reporting to the tomlutil
  • v1.0.1

    • Fixed an issue with cpptoml with trailing whitespace and comments in dates as well as allowing for empty inline tables now.
  • v1.0

    • Reading and writing works. Dates are handeled. Conversion between json, plists and toml works as expected.
  • v0.1.0

    • Basic reading works, no support of Date format yet, or of the switches promised.



Distributed under the MIT License - see LICENSE.txt file for details


  • ObjectiveTOML relies on the excellent cpptoml


ObjectiveTOML is a simple Objective-C Library to read and write TOML files.

License:MIT License


Language:Objective-C 47.4%Language:Objective-C++ 34.1%Language:C++ 18.4%