You can't. The keys of a map can be anything, including objects. But JSON syntax only allows strings as keys. So it's impossible in a general case.
A dynamic JSON file will be created to store the array of JSON objects. Consider, we have a database named gfg, a table named userdata. Now, here is the PHP code to fetch data from database and store them into JSON file named gfgfuserdetails. json by converting them into an array of JSON objects.
I created a ES6 class by Babel and I want to map JSON data which is gotten from a server to the ES6 class.
Is there anything common way to do that?
User.js
export default class User { constructor() { this.firstName; this.lastName; this.sex; } }
app.js
import User from "./classes/User"; var data = JSON.parse(req.responseText); console.log(data.firstname); //Bob //now...just set data one by one?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With