Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

Join multiple objects with one to many relationship

$
0
0

Imagine the following data (array of users which can have many roles, each user object has multiple roleIDs referenced and an array of role definitions):

{"users": [    {"id": 1"roles": [        1,        2      ]    },    {"id": 2"roles": [        1      ]    }      ],"roles": [    {"id": 1"desc": "Viewer"    },    {"id": 2"desc": "admin"    }  ]}

How would you go about joining the two arrays "users" and "roles" in jq to achieve something like this:

"user_roles": [  {    userId: 1,"roles": ["Viewer","admin"    ]  },  {"userId": 2,"roles": ["Viewer"    ]  }]

Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>