{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Developer Portal (Drupal-based) /
avatar image
0
Question by Sakthivel · Jun 09, 2016 at 04:47 PM · 26.5k Views Apigee API

how to write a javascript to get nested JSON array objects like below?

"A": { "B": [ { "B": [ { "B": [ { "B":[] } ] } ] } ] }

Comment
Add comment Show 2
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Anil Sagar @ Google ♦♦   · Jun 09, 2016 at 05:35 PM 0
Link

@Sakthivel , How is this related to Apigee Developer Portal / Apigee Edge ? If it's general programming question please post same in stackoverflow. If it's Apigee related, please explain what you are trying to do with more details.

avatar image Sakthivel · Jun 10, 2016 at 07:35 AM 0
Link

Hi,

my requirement is, when JSON returns the nested array structure like below, i need to write a java script code to extract each "subaddresscomponents"

"subAddress": { "subAddressComponents": [ { "id": "263317533", "subAddressComponents": [ { "id": "263317550", "subAddressComponents": [ { "id": "418703244", } ] } ] } ] }

Close

2 Answers

  • Sort: 
avatar image
0

Answer by sudheendras   · Jun 10, 2016 at 05:33 PM

Hi @Sakthivel Working with JSON objects within a JavaScript policy in Apigee Edge is identical to how you handle it in a regular JavaScript program.

A code snippet like below will go into your JavaScript policy.

var dictionary = {"data":[{"id":"0","name":"ABC"},{"id":"1", "name":"DEF"}], "images": [{"id":"0","name":"PQR"},{"id":"1","name":"xyz"}]};
for (item in dictionary) {
  for (subItem in dictionary[item]) {
     console.log(dictionary[item][subItem]);
  }
}

Checkout this help page here

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Sai Saran Vaidyanathan   · Jun 10, 2016 at 06:01 PM

HI @Sakthivel

You can extract the values using Extract Variables.

<ExtractVariables name="ExtractVariables-3">
   <Source>response</Source>
   <JSONPayload>
      <Variable name="id" type="nodeset">
         <JSONPath>$.subAddress..subAddressComponents[0].id</JSONPath>
      </Variable>
   </JSONPayload>
   <VariablePrefix>subAddressVarPrefix</VariablePrefix>
</ExtractVariables>

This will give you an array of ids --> ["263317533", "263317550", "418703244"]

Similarly you can extract others as well.

Tip: I normally use jsonpath.com to test my json path conditions and then use them in my policy

Hope this helps.

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

38 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

XML to JSON Policy using yahoo format conversions are inconsistent 1 Answer

Recover APIs pages on Pantheon 0 Answers

Where the Dev portal content will be stored ? Shall I retrieve the content by passing some parameters ? Shall I create API proxy and expose as API to query the portal content ? 3 Answers

Issue related to accessing Apigee Edge API through PHP-CURL 0 Answers

is there an API to get data from a console apigee (link with UP, or facebook or other apigee console client) 1 Answer

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges