import { parseJSON , isNil } from '@terascope/utils' ; import { FieldType } from '@terascope/types' ; import { FieldTransformConfig , ProcessMode , FunctionDefinitionType , DataTypeFieldAndChildren , FunctionDefinitionCategory } from '../interfaces' ; export const parseJSONConfig = { name : 'parseJSON' , type : FunctionDefinitionType . FIELD_TRANSFORM , process_mode : ProcessMode . FULL_VALUES , category : FunctionDefinitionCategory . JSON , description : 'Parses a JSON string and returns the value or object according to the arg options.' , create ( ) { return ( input ) => { if ( isNil ( input ) ) return null ; return parseJSON ( input as string ) ; } ; } , accepts : [ FieldType . String ] , argument_schema : { } , output_type ( inputConfig ) { const { field_config } = inputConfig ; return { field_config : { ... field_config , type : FieldType . Any } , } ; } } ;