Supports a predefined configuration that extends JSONDo to manage JSON objects in a dynamicly
Meta
- version: 1.0.0
- author: Justin Mathews
Type defining JSON management instructions
Parameters
-
jsonConfig
JSON Object containing all values needed-
jsonConfig.type
String type Object type that will be found in sourceObject ['static', 'json', 'function'] -
jsonConfig.sourceObject
any Object type passed, must match that defined by "type". Except when type = "static", then the object will be returned as is -
jsonConfig.sourcePath
(String | Array | Undefined) This will either be a (type = 'json') dot '.' delimited string mapping the path to the value (type = 'function') an Array of parameters to pass to the function or Undefined (type = 'static') Undefined - value will be ignored -
jsonConfig.newPath
String dot '.' delimited string mapping the path to the value
-
- See: configType
Returns a value based on the configuration passed. This can a static value or one collected from a JSON object or function call
Parameters
type
sourceObject
sourcePath
-
jsonConfig
JSON Object containing all values needed-
jsonConfig.type
String type Object type that will be found in sourceObject ['static', 'json', 'function'] -
jsonConfig.sourceObject
any Object type passed, must match that defined by "type". Except when type = "static", then the object will be returned as is -
jsonConfig.sourcePath
(String | Array | Undefined) This will either be a (type = 'json') dot '.' delimited string mapping the path to the value (type = 'function') an Array of parameters to pass to the function or Undefined (type = 'static') Undefined - value will be ignored
-
Examples
Retrieve a STATIC value
getValue('static', 'some value', undefined) => 'some value' *
getValue('static', 'some value') => 'some value'
Retrieve a value from JSON
getValue('json', {a:{b:1,c:{d:'value here'}}}, 'a.c.d') => 'value here'
Retrieve value from function call
getValue('function', function bob(){ return 'a value from funtion'}, undefined) => 'a value from funtion'
getValue('function', (input)=>{ return input + 10}, [1]) => 11
getValue('function', (input1, input2)=>{ return input1 + input2}, [1, 100]) => 101
Pass configuration in as JSON object instead of individual parameters
let json = {type: 'static', sourceObject: 'parameters passed in json', sourcePath: undefined}
getValue(json) => 'parameters passed in json'
Returns any
- See: configType
Creates a new JSON object based using a dot '.' delimited String and a value is assign after having retrieved it from the location passed
Parameters
-
jsonConfig
JSON A combination of TYPE configType with an additional field "newPath"
Examples
Using the same process as shown in getValue, an additional step will be added to define and create a nw JSON object with the value provided
let jsonConfig = {type: 'static', sourceObject: 42, newPath: 'answer.to.life.is'}
buildBranch(jsonConfig) => {answer: {to: {life: {is: 42}}}}
Same as above, but the parameters are passed seperately
buildBranch('static', 42, undefined, 'answer.to.life.is') => {answer: {to: {life: {is: 42}}}}
Returns JSON