I don't think this is very easy to do in a robust way with just the built-in modules, so here's a solution that makes use of PyParsing. I took the example jsonParser.py and modified it to recognize strings that don't use quote marks, and added a set literal for your {myaws1, myaws2}
value.
import pyparsing as pp
from pyparsing import pyparsing_common as ppc
def make_keyword(kwd_str, kwd_value):
return pp.Keyword(kwd_str).setParseAction(pp.replaceWith(kwd_value))
TRUE = make_keyword("true", True)
FALSE = make_keyword("false", False)
NULL = make_keyword("null", None)
LBRACK, RBRACK, LBRACE, RBRACE, COLON = map(pp.Suppress, "[]{}:")
jsonString = pp.OneOrMore(pp.CharsNotIn('{}[]:,')).setParseAction(lambda s, l, t: [t[0].strip()])
jsonNumber = ppc.number()
jsonObject = pp.Forward()
jsonValue = pp.Forward()
jsonElements = pp.delimitedList( jsonValue )
jsonArray = pp.Group(LBRACK + pp.Optional(jsonElements, []) + RBRACK)
jsonSet = pp.Group(LBRACE + pp.Optional(jsonElements, []) + RBRACE).setParseAction(lambda s,l,t: set(t[0]))
jsonValue << (jsonNumber | jsonString | pp.Group(jsonObject) | jsonArray | jsonSet | TRUE | FALSE | NULL)
memberDef = pp.Group(jsonString + COLON + jsonValue)
jsonMembers = pp.delimitedList(memberDef)
jsonObject << pp.Dict(LBRACE + pp.Optional(jsonMembers) + RBRACE)
jsonComment = pp.cppStyleComment
jsonObject.ignore(jsonComment)
if __name__ == "__main__":
s ='{source: [s3, kinesis], aws_access_key_id: {myaws1, myaws2}, aws_secret_access_key: REDACTED_POSSIBLE_AWS_SECRET_ACCESS_KEY, bucketName: bucket, region_name: eu-west-1, fileType: zip, typeIngestion: FULL, project: trackingcampaigns, functionalArea: client, filePaths: [s3Sensor/2018/], prefixFiles: [Tracking_Sent, Tracking_Bounces, Tracking_Opens, Tracking_Clicks, Tracking_SendJobs], prefixToTables: {Tracking_Bounces: MNG_TRACKING_EXTRACT_BOUNCES_3, Tracking_Sent: MNG_TRACKING_EXTRACT_SENT_3, Tracking_Clicks: MNG_TRACKING_EXTRACT_CLICKS_3, Tracking_Opens: MNG_TRACKING_EXTRACT_OPENS_3, Tracking_SendJobs: MNG_TRACKING_EXTRACT_SENDJOBS_3}, stagingPath: /zipFiles/}'
results = jsonObject.parseString(s)
print(results.asDict())
Result:
{'source': ['s3', 'kinesis'], 'aws_access_key_id': {'myaws1', 'myaws2'}, 'aws_secret_access_key': 'REDACTED_POSSIBLE_AWS_SECRET_ACCESS_KEY', 'bucketName': 'bucket', 'region_name': 'eu-west-1', 'fileType': 'zip', 'typeIngestion': 'FULL', 'project': 'trackingcampaigns', 'functionalArea': 'client', 'filePaths': ['s3Sensor/2018/'], 'prefixFiles': ['Tracking_Sent', 'Tracking_Bounces', 'Tracking_Opens', 'Tracking_Clicks', 'Tracking_SendJobs'], 'prefixToTables': {'Tracking_Bounces': 'MNG_TRACKING_EXTRACT_BOUNCES_3', 'Tracking_Sent': 'MNG_TRACKING_EXTRACT_SENT_3', 'Tracking_Clicks': 'MNG_TRACKING_EXTRACT_CLICKS_3', 'Tracking_Opens': 'MNG_TRACKING_EXTRACT_OPENS_3', 'Tracking_SendJobs': 'MNG_TRACKING_EXTRACT_SENDJOBS_3'}, 'stagingPath': '/zipFiles/'}
,
and:
to parse your string into a dictionary