Skip to main content

Overview

CloneableJSON extends JSON with data types such as images, locations, and coordinate mappings. Use it to extract, process, and save pole and midspan measurements. CloneableJSON stores flexible data in AnyCloneableData. Components use this wrapper to exchange data.

Reference

  • AnyCloneableData is a type-erased container to hold complex data types
  • CloneableImage stores UIImage data with file persistence capabilities
  • CloneableFileDataType is a protocol for file-based data types that have a UUID identifier

Pole measurement data structure

Pole measurements return this CloneableJSON structure:

Understand CloneableJSON

CloneableJSON uses subscripts that return CloneableJSONValue enums. Accessor methods simplify data access.

Access values

Safe optional access

Throwing access

Direct enum pattern matching

Accessor properties and methods

Optional Properties (return nil if wrong type):

  • .numberValue → Double?
  • .stringValue → String?
  • .boolValue → Bool?
  • .dateValue → Date?
  • .objectValue → [String: CloneableJSONValue]?
  • .arrayValue → [CloneableJSONValue]?
  • .isUndefined → Bool (true if value is undefined)

Throwing Methods (throw JSONError if wrong type):

  • .getNumber() → Double
  • .getString() → String
  • .getBool() → Bool
  • .getDate() → Date
  • .getObject() → [String: CloneableJSONValue]
  • .getArray() → [CloneableJSONValue]

Helper Properties:

  • .typeDescription → String (returns current type: “object”, “array”, “string”, “number”, etc.)

JSONError Types

Work with attachments

Extract attachment data

Extract inventory classifications

Work with images

Extract and save images

Use the AnyCloneableData extension

Work with scaling data

Work with CloneableImage directly

Advanced image operations

Export a JSON string

CloneableJSON provides a built-in method to convert to standard JSON string:
The getJSONValue() method automatically:
  • Converts CloneableImage objects to UUID strings (via getJSONValue() method)
  • Converts CloneableFileDataType objects to UUID strings
  • Converts CloneableNumber to standard JSON numbers
  • Returns pretty-printed, sorted JSON string
  • Preserves complete nested data structure
  • Handles undefined values as null

Schema support

CloneableJSON supports optional schema validation:

Get all file data values

Error handling best practices

When using the throwing accessor methods, you can handle specific error cases:

Best practices

  1. Use optional accessors for exploratory code - When you’re not sure if a value exists or what type it is
  2. Use throwing accessors for production code - When you expect certain data to be present and want clear error messages
  3. Check .isUndefined before accessing nested values - To avoid unnecessary operations
  4. Use .typeDescription for debugging - To understand what type of value you’re dealing with
  5. Prefer the convenience accessors - They’re cleaner and more Swift-like than manual enum matching
  6. Handle CloneableImage download scenarios - Images may need to be downloaded from backend
  7. Use CloneableImage’s built-in file operations - For saving and loading images efficiently
  8. Import UIKit when working with images - CloneableImage uses UIImage which requires UIKit

Quick reference

Your Original Problem - Now Solved!