0

i am now trying to parse AWS http logs in python.I got some logs as below.i would like to convert it to dic.but it seems not standard json because some keys without "".i tried to use json5 but also failed.how can i made it?

{
  resource: '',
  path: '',
  httpMethod: 'POST',
  headers: {
    accept: '*/*',
  },
  multiValueHeaders: {
    accept: [ '*/*' ],
    'accept-encoding': [ 'gzip, deflate, br' ],
    'accept-language': [ 'zh-CN,zh-Hans;q=0.9' ]
  },
  queryStringParameters: {},
  multiValueQueryStringParameters: null,
  pathParameters: null,
  stageVariables: null,
  requestContext: {
    resourceId: '',
    resourcePath: '',
    identity: {
      cognitoIdentityPoolId: null,
      accountId: null,
      cognitoIdentityId: null,
      caller: null,
      sourceIp: '',
      principalOrgId: null,
      accessKey: null,
      cognitoAuthenticationType: null
    },
    domainName: '',
    apiId: ''
  },
  body: [Object: null prototype] { },
  isBase64Encoded: false
}
phoenix
  • 1
  • 1
  • Are you trying to convert this json response to a dictionary in python? – Kavish Baghel Sep 24 '22 at 19:46
  • yes,of course?do u know how to convert this json response to a dictionary in python? – phoenix Sep 24 '22 at 20:40
  • Use json.loads() as recommended in this solution - https://stackoverflow.com/questions/19483351/converting-json-string-to-dictionary-not-list – Kavish Baghel Sep 25 '22 at 17:38
  • i know how to use json.loads(),but the response is not standered json.for example:keys without "" .so if i use json.loads(),i will get json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes.@KavishBaghel – phoenix Sep 26 '22 at 04:56

0 Answers0