• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: need to turn JSON values into keys

Resolved: need to turn JSON values into keys

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have some json that I would like to transform from this:
into this:
For each pair, I need to change the value of the name field to a key, and the values of the intValue field to a value. This doesn’t seem like flattening or denormalizing. Are there any tools that might do this out-of-the-box, or will this have to be brute-forced? What’s the most pythonic way to accomplish this?

Answer:

yields {'field1': '1', 'field2': '2', 'fieldN': 'N'}

or as a dict comprehension


This works to combine the name attribute with the intValue as key:value pairs, but the result is a dictionary instead of the original input type which was a list.

If you have better answer, please add a comment about this, thank you!

python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to convert Java bytecode to Webassembly using CheerpJ compiler

24/03/2023

Resolved: Is pandas groupby() function always produce a DataFrame with the same order respect to the column we group by?

24/03/2023

Resolved: Kivy widget hierarchy not behaving as expected

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.