commandbox.system.services

Class JSONService

lucee.Component
    extended by commandbox.system.services.JSONService

Copyright Since 2014 CommandBox by Ortus Solutions, Corp www.coldbox.org | www.ortussolutions.com I am a collection of shared functionality for dealing with JSON files

Class Attributes:
  • singleton
  •  
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
  • author : Brad Wood, Luis Majano
  •  
    Property Summary
    type property default serializable required
    any configService


    • access = public
    • returntype = any
    • inject = ConfigService
    true false
    any fileSystemUtil


    • access = public
    • returntype = any
    • inject = FileSystem
    true false
    any formatterUtil


    • access = public
    • returntype = any
    • inject = Formatter
    true false
    any logger


    • access = public
    • returntype = any
    • inject = logbox:logger:{this}
    true false
    any print


    • access = public
    • returntype = any
    • inject = print
    true false
    Constructor Summary
    init()
          Constructor.
    Method Summary
    any addProp([any props], [any prop], [any safeProp], [any targetStruct])
    boolean check(any JSON, string property)
         I check for the existance of a property.
    any clear(any JSON, string property)
         I clear a property from a deserialized JSON object.
    any getANSIColors()
         Get ANSI colors for formatting JSON.
    string getConfigService()
    string getFileSystemUtil()
    string getFormatterUtil()
    string getLogger()
    string getPrint()
    any isSortedJSON(any json, string sortKeys)
         I check to see if a JSON object has sorted keys.
    any set(any JSON, struct properties, boolean thisAppend)
         I set a property from a deserialized JSON object and returns an array of messages regarding the word that was done.
    any setConfigService(any configService)
    any setFileSystemUtil(any fileSystemUtil)
    any setFormatterUtil(any formatterUtil)
    any setLogger(any logger)
    any setPrint(any print)
    any show(any JSON, string property, [any defaultValue])
         I get a property from a deserialized JSON object and return it.
    private any toBracketNotation(string property)
    any writeJSONFile(string path, any json, [boolean locking='false'])
         I write JSON objects to disk after pretty printing them.
     
    Methods inherited from class lucee.Component
    None

    Constructor Detail

    init

    public init()

    Constructor


    Property Detail

    configService

    property any configService

    Attributes:
    access - public
    required - false
    returntype - any
    inject - ConfigService
    serializable - true

    fileSystemUtil

    property any fileSystemUtil

    Attributes:
    access - public
    required - false
    returntype - any
    inject - FileSystem
    serializable - true

    formatterUtil

    property any formatterUtil

    Attributes:
    access - public
    required - false
    returntype - any
    inject - Formatter
    serializable - true

    logger

    property any logger

    Attributes:
    access - public
    required - false
    returntype - any
    inject - logbox:logger:{this}
    serializable - true

    print

    property any print

    Attributes:
    access - public
    required - false
    returntype - any
    inject - print
    serializable - true

    Method Detail

    addProp

    public any addProp([any props], [any prop], [any safeProp], [any targetStruct])

    Parameters:
    props
    prop
    safeProp
    targetStruct

    check

    public boolean check(any JSON, string property)

    I check for the existance of a property

    Parameters:
    JSON
    property

    clear

    public any clear(any JSON, string property)

    I clear a property from a deserialized JSON object.

    Parameters:
    JSON
    property

    getANSIColors

    public any getANSIColors()

    Get ANSI colors for formatting JSON. Returns defaults if no settings are present


    getConfigService

    public string getConfigService()


    getFileSystemUtil

    public string getFileSystemUtil()


    getFormatterUtil

    public string getFormatterUtil()


    getLogger

    public string getLogger()


    getPrint

    public string getPrint()


    isSortedJSON

    public any isSortedJSON(any json, string sortKeys)

    I check to see if a JSON object has sorted keys. (I also work for CFML objects that can be serialized to JSON.)

    Parameters:
    json - A string containing JSON, or a complex value that can be serialized to JSON
    sortKeys - The type of key sorting to check for - i.e. "text" or "textnocase"

    set

    public any set(any JSON, struct properties, boolean thisAppend)

    I set a property from a deserialized JSON object and returns an array of messages regarding the word that was done.

    Parameters:
    JSON
    properties
    thisAppend

    setConfigService

    public any setConfigService(any configService)

    Parameters:
    configService

    setFileSystemUtil

    public any setFileSystemUtil(any fileSystemUtil)

    Parameters:
    fileSystemUtil

    setFormatterUtil

    public any setFormatterUtil(any formatterUtil)

    Parameters:
    formatterUtil

    setLogger

    public any setLogger(any logger)

    Parameters:
    logger

    setPrint

    public any setPrint(any print)

    Parameters:
    print

    show

    public any show(any JSON, string property, [any defaultValue])

    I get a property from a deserialized JSON object and return it

    Parameters:
    JSON
    property
    defaultValue

    toBracketNotation

    private any toBracketNotation(string property)

    Parameters:
    property

    writeJSONFile

    public any writeJSONFile(string path, any json, [boolean locking='false'])

    I write JSON objects to disk after pretty printing them. (I also work for CFML objects that can be serialized to JSON.)

    Parameters:
    path - The file path to write to
    json - A string containing JSON, or a complex value that can be serialized to JSON
    locking - Set to true to have file system access wrapped in a lock