Using python socket I am receiving value as a string and want to store the value in SQLite DB as dictionary key to column and values as a row.
So for that purpose, I am not able to convert the string to dictionary -
ReceivedValue = [{'Value1': 'OutPut00', 'Value2': 'OutPut01', 'Value3': '2253.23'},{'Value1': 'NA', 'Value3': 'NA'}]
ReceivedValue always returns str type instead list and stopping me to process further to add in SQLite DB.
How can I convert this received value to a Dictionary or list of dictionaries?
Json Approach EDIT:1 - Attached the required screenshot for Json Error
eval Approach EDIT:2 -
def process(ReceivedValue):
print ReceivedValue
finVal = ast.literal_eval(ReceivedValue)
print finVal
print type(finVal)
OutPut -
"[{'APACHE_MODJK': '1.2.41', 'PROCESSOR_MODEL': ' Intel(R) Xeon(R) CPU E5-2680 0 @ 2.70GHz', 'APACHE_HOME': '/opt/www/apache/2.4.17', 'OS_KERNEL': '2.6.32-573.26.1.el6.x86_64', 'APACHE_SSO': 'YES', 'TOMCAT_VER': 'NA', 'ENV': 'PROD', 'APACHE': 'RUNNING', 'JBOSS_HOME': '/opt/www/jboss/4.3/jboss-as', 'APACHE_VIP': 'NA', 'CPU': 2, 'OS_VER': 'Red Hat Enterprise Linux Server release 6.7 (Santiago)', 'TOMCAT_DB': 'NA', 'SAN': 'NA', 'JBOSS_DB': 'p377', 'MEMORY': 4, 'JBOSS_VER': '4.3.0.GA_CP02', 'JDK_VER': '1.6.0_18', 'APACHE_VER': '2.4.17', 'MACHINE_TYPE': 'VMware Virtual Platform'}]"
[{'APACHE_MODJK': '1.2.41', 'PROCESSOR_MODEL': ' Intel(R) Xeon(R) CPU E5-2680 0 @ 2.70GHz', 'APACHE_HOME': '/opt/www/apache/2.4.17', 'OS_KERNEL': '2.6.32-573.26.1.el6.x86_64', 'APACHE_SSO': 'YES', 'TOMCAT_VER': 'NA', 'ENV': 'PROD', 'APACHE': 'RUNNING', 'JBOSS_HOME': '/opt/www/jboss/4.3/jboss-as', 'APACHE_VIP': 'NA', 'CPU': 2, 'OS_VER': 'Red Hat Enterprise Linux Server release 6.7 (Santiago)', 'TOMCAT_DB': 'NA', 'SAN': 'NA', 'MEMORY': 4, 'JBOSS_VER': '4.3.0.GA_CP02', 'JDK_VER': '1.6.0_18', 'APACHE_VER': '2.4.17', 'MACHINE_TYPE': 'VMware Virtual Platform'}]
<type 'str'>
WORKING SOLUTION: Just Removed the double quotes from the RecievedValue to evaluate it across eval() or ast.literal_eval()
evalfunction, but that's a potential security issueeval,ast.literal_evaldoes the job and is safe.