go to post Duc Anh Tran · Oct 6, 2018 I have a last question Is it possible to import my collection row by row for like every 5 seconds? I want to create a streaming and always want to refresh my database. I think it's also okay if i can import my whole collection for like every hour. Thank you again in adance.
go to post Duc Anh Tran · Oct 5, 2018 Im trying to store the properties "name", "playcount", "listeners", "mbid", "url" not the "artist" or the "artists" property. I think that my document class definition is at the bottom of my code :Class User.API{ClassMethod getFile() as %Status{ IF $SYSTEM.DocDB.Exists("db.Streamingdatabase") { SET db = ##class(%DocDB.Database).%GetDatabase("db.Streamingdatabase") } ELSE { SET db = ##class(%DocDB.Database).%CreateDatabase("db.Streamingdatabase") } DO db.%CreateProperty("Name","%String(MAXLEN=200)","$.name") DO db.%CreateProperty("Duration","%Integer","$.duration") DO db.%CreateProperty("Playcount","%Integer","$.playcount") DO db.%CreateProperty("Mbid","%String(MAXLEN=200)","$.mbid") DO db.%CreateProperty("Url","%String(MAXLEN=200)","$.url") DO db.%CreateProperty("StreamableText","%Integer","$.streamable/#text") DO db.%CreateProperty("StreamableFulltrack","%Integer","$.streamable/fulltrack") DO db.%CreateProperty("ArtistName","%String(MAXLEN=200)","$.artist/name") DO db.%CreateProperty("ArtistMbid","%String(MAXLEN=200)","$.artist/mbid") DO db.%CreateProperty("ArtistURL","%String(MAXLEN=200)","$.artist/url") DO db.%CreateProperty("Rank","%Integer","$.@attr/rank") SET httprequest=##class(%Net.HttpRequest).%New() DO httprequest.Get("http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=ducanhtr...") DO db.%FromJSON(httprequest.HttpResponse.Data) }}
go to post Duc Anh Tran · Oct 5, 2018 Sorry i still don't know how to parse it. I only need the body of my JSON formatted data from my API. How can i only take the body of my API and import it to my docdb?For example:{ "artists": { "artist": [ { "name": "Tough Love", "playcount": "279426", "listeners": "58179", "mbid": "d07276bc-3874-4deb-8699-35c9948be0cc", "url": "https://www.last.fm/music/Tough+Love", "streamable": "0", "image": [ { "#text": "https://lastfm-img2.akamaized.net/i/u/34s/3fa24f60a855fdade245138dead7ec...", "size": "small" }, { "#text": "https://lastfm-img2.akamaized.net/i/u/64s/3fa24f60a855fdade245138dead7ec...", "size": "medium" }, { "#text": "https://lastfm-img2.akamaized.net/i/u/174s/3fa24f60a855fdade245138dead7e...", "size": "large" }, { "#text": "https://lastfm-img2.akamaized.net/i/u/300x300/3fa24f60a855fdade245138dea...", "size": "extralarge" }, { "#text": "https://lastfm-img2.akamaized.net/i/u/300x300/3fa24f60a855fdade245138dea...", "size": "mega" } ]This is a part of my JSON formatted data from my API and i only need the "name", "playcount", "listeners" and so on as my headers without "artists" and without "artist". Do i need to parse it? Or is there another possibility how i can leave off the first two header?Thank you in advance.
go to post Duc Anh Tran · Oct 4, 2018 Thank you very much Steve! I imported my JSON formatted API to my database and my code looks like this:Class User.API{ClassMethod getFile() as %Status{ IF $SYSTEM.DocDB.Exists("db.Streamingdatabase") { SET db = ##class(%DocDB.Database).%GetDatabase("db.Streamingdatabase") } ELSE { SET db = ##class(%DocDB.Database).%CreateDatabase("db.Streamingdatabase") } DO db.%CreateProperty("Name","%String(MAXLEN=200)","$.name") DO db.%CreateProperty("Duration","%Integer","$.duration") DO db.%CreateProperty("Playcount","%Integer","$.playcount") DO db.%CreateProperty("Mbid","%String(MAXLEN=200)","$.mbid") DO db.%CreateProperty("Url","%String(MAXLEN=200)","$.url") DO db.%CreateProperty("StreamableText","%Integer","$.streamable/#text") DO db.%CreateProperty("StreamableFulltrack","%Integer","$.streamable/fulltrack") DO db.%CreateProperty("ArtistName","%String(MAXLEN=200)","$.artist/name") DO db.%CreateProperty("ArtistMbid","%String(MAXLEN=200)","$.artist/mbid") DO db.%CreateProperty("ArtistURL","%String(MAXLEN=200)","$.artist/url") DO db.%CreateProperty("Rank","%Integer","$.@attr/rank") SET httprequest=##class(%Net.HttpRequest).%New() DO httprequest.Get("http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=ducanhtr...") DO db.%FromJSON(httprequest.HttpResponse.Data) }} But now i have the problem that my JSON formatted data from my API is imported only to the %Doc column. I think that the document database only puts my information from my API to the right columns if my JSON is in a JSONArrray format. But the format of my API is JSONObject. Is there a possibility to convert the format from JSONObject to JSONArray? Best regards, Duc Anh