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 Consolelogger


    • access = public
    • returntype = any
    • inject = logbox:logger:console
    true false
    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 jmespath


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


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


    • access = public
    • returntype = any
    • inject = parser
    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 existence of a property.
    any clear(any JSON, string property)
         I clear a property from a deserialized JSON object.
    private any findArrays(string property)
    any getANSIColors()
         Get ANSI colors for formatting JSON.
    string getConfigService()
    string getConsolelogger()
    string getFileSystemUtil()
    string getFormatterUtil()
    string getJmespath()
    string getLogger()
    string getParser()
    string getPrint()
    any isSortedJSON(any json, string sortKeys)
         I check to see if a JSON object has sorted keys.
    any mergeData([any target], [any source])
         Merges data from source into target.
    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 setConsolelogger(any Consolelogger)
    any setFileSystemUtil(any fileSystemUtil)
    any setFormatterUtil(any formatterUtil)
    any setJmespath(any jmespath)
    any setLogger(any logger)
    any setParser(any parser)
    any setPrint(any print)
    any show(any JSON, string property, [any defaultValue])
         I get a property from a deserialized JSON object and return it.
    any showJMES(any JSON, string property, [any defaultValue])
         I get a property from a deserialized JSON object and return it using JMESPath.
    private any toBracketNotation(any property)
    private any toJMESNotation([any str])
    any tokenizeProp(string str)
    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

    Consolelogger

    property any Consolelogger

    Attributes:
    access - public
    required - false
    returntype - any
    inject - logbox:logger:console
    serializable - true

    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

    jmespath

    property any jmespath

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

    logger

    property any logger

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

    parser

    property any parser

    Attributes:
    access - public
    required - false
    returntype - any
    inject - parser
    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 existence 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

    findArrays

    private any findArrays(string property)

    Parameters:
    property

    getANSIColors

    public any getANSIColors()

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


    getConfigService

    public string getConfigService()


    getConsolelogger

    public string getConsolelogger()


    getFileSystemUtil

    public string getFileSystemUtil()


    getFormatterUtil

    public string getFormatterUtil()


    getJmespath

    public string getJmespath()


    getLogger

    public string getLogger()


    getParser

    public string getParser()


    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"

    mergeData

    public any mergeData([any target], [any source])

    Merges data from source into target

    Parameters:
    target
    source

    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

    setConsolelogger

    public any setConsolelogger(any Consolelogger)

    Parameters:
    Consolelogger

    setFileSystemUtil

    public any setFileSystemUtil(any fileSystemUtil)

    Parameters:
    fileSystemUtil

    setFormatterUtil

    public any setFormatterUtil(any formatterUtil)

    Parameters:
    formatterUtil

    setJmespath

    public any setJmespath(any jmespath)

    Parameters:
    jmespath

    setLogger

    public any setLogger(any logger)

    Parameters:
    logger

    setParser

    public any setParser(any parser)

    Parameters:
    parser

    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

    showJMES

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

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

    Parameters:
    JSON
    property
    defaultValue

    toBracketNotation

    private any toBracketNotation(any property)

    Parameters:
    property

    toJMESNotation

    private any toJMESNotation([any str])

    Parameters:
    str

    tokenizeProp

    public any tokenizeProp(string str)

    Parameters:
    str

    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