Currently I have a JSON from which I want to extract certain specific data, for example I want to extract the
ID - Username - IP
Object from the JSON
Currently I have been trying with this code but it is not giving me the adequate results
var json = '42["getUsers",{"1620552418669":{"role":"guest","image":"/img/avatars/m/3.svg","startRoom":0,"expired":false,"free":false,"entries":"255042500","streamName":1620552397,"roles":{"canKick":"0","canBan":"0","canMute":false,"canSpyWhisperMessages":"0","canDeleteUserMessages":"0"},"country":"MX","webmasterid":1,"id":1620552418669,"username":"luis fdo5544","isGuest":true,"gender":"hombre","hasFlash":false,"hasWebcam":false,"hasWebrtc":true,"room":{"id":"47","name":"Más de 40","description":"La sala para mayores de 40 años.","welcome":"","date":"2019-12-07 16:12:02","destructionDate":"0000-00-00 00:00:00","webmasterid":"1","users":67,"password":"","image":"/upload/rooms/2tjdhjliih0ks0wggg.jpg","default":"0","webcam":"0","colorPicker":"1","isTemporary":"0","ownerid":"0","maxUsers":"150","reservedToGenderid":"0","orderRoom":"86","inPrivateConference":"0","isAdult":"0","reservedToRoles":"0","tags":"","country":"","numberFavorit":"298","approved":"0","deleted":"0","reservedToGenderidCondition":"Equals","reservedToRolesCondition":"Equals","urlImage":"","isHidden":"0","radio_url":"","radio_start":"1"},"webcam":false,"status":"online","webcamPublic":false,"privateOnlyOnInvitation":true,"credits":0,"e":"","isMobile":false,"fingerprint":1457712961,"enterChatMode":true,"friends":{},"doNotAcceptPrivate":true,"myFavouriteRooms":[],"oldRole":"guest","gotBackground":true,"roomsIn":[49,48,47],"rouletteBusy":true,"socketid":"VCqjrZXOyygqHUJIBcQO","ip":2806,"password":"","email":""},"1620555811311":{"role":"guest","image":"/img/avatars/m/18.svg","startRoom":0,"expired":false,"free":false,"entries":"255043519","streamName":1620555757,"roles":{"canKick":"0","canBan":"0","canMute":false,"canSpyWhisperMessages":"0","canDeleteUserMessages":"0"},"country":"SE","webmasterid":1,"id":1620555811311,"username":"xhip","isGuest":true,"gender":"hombre","hasFlash":false,"hasWebcam":false,"hasWebrtc":true,"room":{"id":"48","name":"Más de 50","description":"La sala para mayores de 50 años.","welcome":"","date":"2019-12-07 16:12:30","destructionDate":"0000-00-00 00:00:00","webmasterid":"1","users":1,"password":"","image":"/upload/rooms/s7eqp5bzxn4844c844.png","default":"0","webcam":"0","colorPicker":"1","isTemporary":"0","ownerid":"0","maxUsers":"115","reservedToGenderid":"0","orderRoom":"84","inPrivateConference":"0","isAdult":"0","reservedToRoles":"0","tags":"","country":"","numberFavorit":"234","approved":"0","deleted":"0","reservedToGenderidCondition":"Equals","reservedToRolesCondition":"Equals","urlImage":"","isHidden":"0","radio_url":"","radio_start":"1"},"webcam":false,"status":"online","webcamPublic":false,"privateOnlyOnInvitation":true,"credits":0,"e":"","isMobile":false,"fingerprint":-1200890177,"enterChatMode":true,"friends":{},"doNotAcceptPrivate":true,"myFavouriteRooms":[],"oldRole":"guest","rouletteBusy":true,"socketid":"mOPdOA1S2QDKozzKBcju","ip":3113473371,"roomsIn":[48],"password":"","email":""}},"48"]';
var parsed = JSON.parse(json.substr(2, json.length));
var newjson = (parsed);
newjson.forEach((obj) => {
for (const [key, value] of Object.entries(obj)) {
console.log(`${key} - ${value}`);
}
});
Does anyone know how I can correct the code and get the expected results?.
Thanks.
[]?.lodashit has_getand other utilities, that can help. lodash.com