Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Python callout In Apigee

I am trying to use json.dumps and json.load but getting error 

 \"NameError: name 'json' is not defined\
 
Is there any way to import json module in Python script in Apigee.
0 2 246
2 REPLIES 2

Hello @vishalvekaria19, thank you for reaching to the Apigee forum. Just a quick note to help keep the forum organized - please try to focus on one post per question, as this helps streamline responses and keeps things tidy.

Additionally, it would be helpful if you could provide more details about your issue to help community members to better understand and provide relevant solutions. Thank you 😊

Hey @vishalvekaria19, according to the documentation, Python language support is provided through Jython version 2.5.2, which doesn't have a native JSON module.

You should consider using JavaScript policy if you want to parse JSON objects.

var requestContent = context.getVariable('request.content');
try {
  var parsedRequestContent = JSON.parse(requestContent);
} catch (e) {
  throw new Error('request content is not a JSON');
}
// Continue with other code using parsedRequestContent
// ...