5 added 444 characters in body
source | link

What you are getting is not "CDF format" but a Mathematica Dataset. You should also note that you are trying to convert and serve a dataset that has 45716 entries. This might well run into limits (cputime, memory, transfered data) of an APIFunction. I am also not sure whether WRI will allow you to provide a possibility to download complete resource-data datasets, you would have to check their legal conditions. Finally you should note that there is already a possibility to download the whole dataset from https://datarepository.wolframcloud.com/resources/Meteorite-Landings, although the JSON that is delivered looks a bit special (it is a Mathematica expression expressed as JSON arrays, probably not what one would expect...).

Using the following code in your API function should convert the first 10 entries into a JSON equivalent of the Dataset:

api=APIFunction[{"tablename" -> "String"},ExportString[
 (Take[ResourceData[ResourceObject[#tablename]],10] // Normal) //. {
 a_Association :> Normal[a],
 q_Quantity :> QuantityMagnitude[q],
 d_DateObject :> d@"Year",
 g_GeoPosition :> {Latitude[g], Longitude[g]}
}, "JSON","Compact"->True] &,"String"]

What it does is to convert the Dataset into a list of rules using Normal (as ExportString[_,"JSON"] can not directly digest the Dataset). It then converts all elements that can not directly be exported to something equivalent that can be exported. Check the documentation for more details about the various data types and functions used. I also added the option "Compact"->True for ExportString which will make the result more compact (it avoids formatting with tabs and newlines) and an additional explicit format argument to APIFunction which will make the APIFunction return the JSON string itself instead of a Mathematica string containing the JSON string (which basically means an extra set of "). This way the APIFunction should behave more like one would expect.

As you seem to have problems to get the APIFunction to work, here is example code which shows how to deploy the APIFunction:

co = CloudDeploy[api, Permissions -> "Public"];

... check that it works correctly (note that you need to include the space in "tablename" and URL-encode it, which URLBuild will conveniently do for you):

Import[URLBuild[co, {"tablename" -> "Meteorite Landings"}], "RawJSON"]

... and finally remove the public api (you probably don't want it to linger around and let others consume your cloud credits):

DeleteFile[co]

One more tip when working with such code: I would only deploy some functionality to the cloud once it works locally. In your case you could for example test the conversion to JSON entirely on your local machine without spending any cloud credits and resulting anin a much faster loop while developing/testing:

data = ResourceData[ResourceObject["Meteorite Landings"]]

Length[data]

Take[data, 10]

ExportString[(Take[data, 10] // Normal) //. {a_Association :> 
  Normal[a], q_Quantity :> QuantityMagnitude[q], 
  d_DateObject :> d@"Year", 
  g_GeoPosition :> {Latitude[g], Longitude[g]}}, "JSON"]

What you are getting is not "CDF format" but a Mathematica Dataset. You should also note that you are trying to convert and serve a dataset that has 45716 entries. This might well run into limits (cputime, memory, transfered data) of an APIFunction. I am also not sure whether WRI will allow you to provide a possibility to download complete resource-data datasets, you would have to check their legal conditions. Finally you should note that there is already a possibility to download the whole dataset from https://datarepository.wolframcloud.com/resources/Meteorite-Landings, although the JSON that is delivered looks a bit special (it is a Mathematica expression expressed as JSON arrays, probably not what one would expect...).

Using the following code in your API function should convert the first 10 entries into a JSON equivalent of the Dataset:

api=APIFunction[{"tablename" -> "String"},ExportString[
 (Take[ResourceData[ResourceObject[#tablename]],10] // Normal) //. {
 a_Association :> Normal[a],
 q_Quantity :> QuantityMagnitude[q],
 d_DateObject :> d@"Year",
 g_GeoPosition :> {Latitude[g], Longitude[g]}
}, "JSON","Compact"->True] &,"String"]

What it does is to convert the Dataset into a list of rules using Normal (as ExportString[_,"JSON"] can not directly digest the Dataset). It then converts all elements that can not directly be exported to something equivalent that can be exported. Check the documentation for more details about the various data types and functions used.

As you seem to have problems to get the APIFunction to work, here is example code which shows how to deploy the APIFunction:

co = CloudDeploy[api, Permissions -> "Public"];

... check that it works correctly (note that you need to include the space in "tablename" and URL-encode it, which URLBuild will conveniently do for you):

Import[URLBuild[co, {"tablename" -> "Meteorite Landings"}], "RawJSON"]

... and finally remove the public api (you probably don't want it to linger around and let others consume your cloud credits):

DeleteFile[co]

One more tip when working with such code: I would only deploy some functionality to the cloud once it works locally. In your case you could for example test the conversion to JSON entirely on your local machine without spending any cloud credits and resulting an a much faster loop while developing/testing:

data = ResourceData[ResourceObject["Meteorite Landings"]]

Length[data]

Take[data, 10]

ExportString[(Take[data, 10] // Normal) //. {a_Association :> 
  Normal[a], q_Quantity :> QuantityMagnitude[q], 
  d_DateObject :> d@"Year", 
  g_GeoPosition :> {Latitude[g], Longitude[g]}}, "JSON"]

What you are getting is not "CDF format" but a Mathematica Dataset. You should also note that you are trying to convert and serve a dataset that has 45716 entries. This might well run into limits (cputime, memory, transfered data) of an APIFunction. I am also not sure whether WRI will allow you to provide a possibility to download complete resource-data datasets, you would have to check their legal conditions. Finally you should note that there is already a possibility to download the whole dataset from https://datarepository.wolframcloud.com/resources/Meteorite-Landings, although the JSON that is delivered looks a bit special (it is a Mathematica expression expressed as JSON arrays, probably not what one would expect...).

Using the following code in your API function should convert the first 10 entries into a JSON equivalent of the Dataset:

api=APIFunction[{"tablename" -> "String"},ExportString[
 (Take[ResourceData[ResourceObject[#tablename]],10] // Normal) //. {
 a_Association :> Normal[a],
 q_Quantity :> QuantityMagnitude[q],
 d_DateObject :> d@"Year",
 g_GeoPosition :> {Latitude[g], Longitude[g]}
}, "JSON","Compact"->True] &,"String"]

What it does is to convert the Dataset into a list of rules using Normal (as ExportString[_,"JSON"] can not directly digest the Dataset). It then converts all elements that can not directly be exported to something equivalent that can be exported. Check the documentation for more details about the various data types and functions used. I also added the option "Compact"->True for ExportString which will make the result more compact (it avoids formatting with tabs and newlines) and an additional explicit format argument to APIFunction which will make the APIFunction return the JSON string itself instead of a Mathematica string containing the JSON string (which basically means an extra set of "). This way the APIFunction should behave more like one would expect.

As you seem to have problems to get the APIFunction to work, here is example code which shows how to deploy the APIFunction:

co = CloudDeploy[api, Permissions -> "Public"];

... check that it works correctly (note that you need to include the space in "tablename" and URL-encode it, which URLBuild will conveniently do for you):

Import[URLBuild[co, {"tablename" -> "Meteorite Landings"}], "RawJSON"]

... and finally remove the public api (you probably don't want it to linger around and let others consume your cloud credits):

DeleteFile[co]

One more tip when working with such code: I would only deploy some functionality to the cloud once it works locally. In your case you could for example test the conversion to JSON entirely on your local machine without spending any cloud credits and resulting in a much faster loop while developing/testing:

data = ResourceData[ResourceObject["Meteorite Landings"]]

Length[data]

Take[data, 10]

ExportString[(Take[data, 10] // Normal) //. {a_Association :> 
  Normal[a], q_Quantity :> QuantityMagnitude[q], 
  d_DateObject :> d@"Year", 
  g_GeoPosition :> {Latitude[g], Longitude[g]}}, "JSON"]
4 added explicit format argument to APIFunction
source | link

What you are getting is not "CDF format" but a Mathematica Dataset. You should also note that you are trying to convert and serve a dataset that has 45716 entries. This might well run into limits (cputime, memory, transfered data) of an APIFunction. I am also not sure whether WRI will allow you to provide a possibility to download complete resource-data datasets, you would have to check their legal conditions. Finally you should note that there is already a possibility to download the whole dataset from https://datarepository.wolframcloud.com/resources/Meteorite-Landings, although the JSON that is delivered looks a bit special (it is a Mathematica expression expressed as JSON arrays, probably not what one would expect...).

Using the following code in your API function should convert the first 10 entries into a JSON equivalent of the Dataset:

api=APIFunction[{"tablename" -> "String"},ExportString[
 (Take[ResourceData[ResourceObject[#tablename]],10] // Normal) //. {
 a_Association :> Normal[a],
 q_Quantity :> QuantityMagnitude[q],
 d_DateObject :> d@"Year",
 g_GeoPosition :> {Latitude[g], Longitude[g]}
}, "JSON"]"JSON","Compact"->True] &]&,"String"]

What it does is to convert the Dataset into a list of rules using Normal (as ExportString[_,"JSON"] can not directly digest the Dataset). It then converts all elements that can not directly be exported to something equivalent that can be exported. Check the documentation for more details about the various data types and functions used.

As you seem to have problems to get the APIFunction to work, here is example code which shows how to deploy the APIFunction:

co = CloudDeploy[api, Permissions -> "Public"];

... check that it works correctly (note that you need to include the space in "tablename" and URL-encode it, which URLBuild will conveniently do for you):

Import[URLBuild[co, {"tablename" -> "Meteorite Landings"}], "RawJSON"]

... and finally remove the public api (you probably don't want it to linger around and let others consume your cloud credits):

DeleteFile[co]

One more tip when working with such code: I would only deploy some functionality to the cloud once it works locally. In your case you could for example test the conversion to JSON entirely on your local machine without spending any cloud credits and resulting an a much faster loop while developing/testing:

data = ResourceData[ResourceObject["Meteorite Landings"]]

Length[data]

Take[data, 10]

ExportString[(Take[data, 10] // Normal) //. {a_Association :> 
  Normal[a], q_Quantity :> QuantityMagnitude[q], 
  d_DateObject :> d@"Year", 
  g_GeoPosition :> {Latitude[g], Longitude[g]}}, "JSON"]

What you are getting is not "CDF format" but a Mathematica Dataset. You should also note that you are trying to convert and serve a dataset that has 45716 entries. This might well run into limits (cputime, memory, transfered data) of an APIFunction. I am also not sure whether WRI will allow you to provide a possibility to download complete resource-data datasets, you would have to check their legal conditions. Finally you should note that there is already a possibility to download the whole dataset from https://datarepository.wolframcloud.com/resources/Meteorite-Landings, although the JSON that is delivered looks a bit special (it is a Mathematica expression expressed as JSON arrays, probably not what one would expect...).

Using the following code in your API function should convert the first 10 entries into a JSON equivalent of the Dataset:

api=APIFunction[{"tablename" -> "String"},ExportString[
 (Take[ResourceData[ResourceObject[#tablename]],10] // Normal) //. {
 a_Association :> Normal[a],
 q_Quantity :> QuantityMagnitude[q],
 d_DateObject :> d@"Year",
 g_GeoPosition :> {Latitude[g], Longitude[g]}
}, "JSON"] &]

What it does is to convert the Dataset into a list of rules using Normal (as ExportString[_,"JSON"] can not directly digest the Dataset). It then converts all elements that can not directly be exported to something equivalent that can be exported. Check the documentation for more details about the various data types and functions used.

As you seem to have problems to get the APIFunction to work, here is example code which shows how to deploy the APIFunction:

co = CloudDeploy[api, Permissions -> "Public"];

... check that it works correctly (note that you need to include the space in "tablename" and URL-encode it, which URLBuild will conveniently do for you):

Import[URLBuild[co, {"tablename" -> "Meteorite Landings"}], "RawJSON"]

... and finally remove the public api (you probably don't want it to linger around and let others consume your cloud credits):

DeleteFile[co]

One more tip when working with such code: I would only deploy some functionality to the cloud once it works locally. In your case you could for example test the conversion to JSON entirely on your local machine without spending any cloud credits and resulting an a much faster loop while developing/testing:

data = ResourceData[ResourceObject["Meteorite Landings"]]

Length[data]

Take[data, 10]

ExportString[(Take[data, 10] // Normal) //. {a_Association :> 
  Normal[a], q_Quantity :> QuantityMagnitude[q], 
  d_DateObject :> d@"Year", 
  g_GeoPosition :> {Latitude[g], Longitude[g]}}, "JSON"]

What you are getting is not "CDF format" but a Mathematica Dataset. You should also note that you are trying to convert and serve a dataset that has 45716 entries. This might well run into limits (cputime, memory, transfered data) of an APIFunction. I am also not sure whether WRI will allow you to provide a possibility to download complete resource-data datasets, you would have to check their legal conditions. Finally you should note that there is already a possibility to download the whole dataset from https://datarepository.wolframcloud.com/resources/Meteorite-Landings, although the JSON that is delivered looks a bit special (it is a Mathematica expression expressed as JSON arrays, probably not what one would expect...).

Using the following code in your API function should convert the first 10 entries into a JSON equivalent of the Dataset:

api=APIFunction[{"tablename" -> "String"},ExportString[
 (Take[ResourceData[ResourceObject[#tablename]],10] // Normal) //. {
 a_Association :> Normal[a],
 q_Quantity :> QuantityMagnitude[q],
 d_DateObject :> d@"Year",
 g_GeoPosition :> {Latitude[g], Longitude[g]}
}, "JSON","Compact"->True] &,"String"]

What it does is to convert the Dataset into a list of rules using Normal (as ExportString[_,"JSON"] can not directly digest the Dataset). It then converts all elements that can not directly be exported to something equivalent that can be exported. Check the documentation for more details about the various data types and functions used.

As you seem to have problems to get the APIFunction to work, here is example code which shows how to deploy the APIFunction:

co = CloudDeploy[api, Permissions -> "Public"];

... check that it works correctly (note that you need to include the space in "tablename" and URL-encode it, which URLBuild will conveniently do for you):

Import[URLBuild[co, {"tablename" -> "Meteorite Landings"}], "RawJSON"]

... and finally remove the public api (you probably don't want it to linger around and let others consume your cloud credits):

DeleteFile[co]

One more tip when working with such code: I would only deploy some functionality to the cloud once it works locally. In your case you could for example test the conversion to JSON entirely on your local machine without spending any cloud credits and resulting an a much faster loop while developing/testing:

data = ResourceData[ResourceObject["Meteorite Landings"]]

Length[data]

Take[data, 10]

ExportString[(Take[data, 10] // Normal) //. {a_Association :> 
  Normal[a], q_Quantity :> QuantityMagnitude[q], 
  d_DateObject :> d@"Year", 
  g_GeoPosition :> {Latitude[g], Longitude[g]}}, "JSON"]
3 added 640 characters in body
source | link

What you are getting is not "CDF format" but a Mathematica Dataset. You should also note that you are trying to convert and serve a dataset that has 45716 entries. This might well run into limits (cputime, memory, transfered data) of an APIFunction. I am also not sure whether WRI will allow you to provide a possibility to download complete resource-data datasets, you would have to check their legal conditions. Finally you should note that there is already a possibility to download the whole dataset from https://datarepository.wolframcloud.com/resources/Meteorite-Landings, although the JSON that is delivered looks a bit special (it is a Mathematica expression expressed as JSON arrays, probably not what one would expect...).

Using the following code in your API function should convert the first 10 entries into a JSON equivalent of the Dataset:

api=APIFunction[{"tablename" -> "String"},ExportString[
 (Take[ResourceData[ResourceObject[#tablename]],10] // Normal) //. {
 a_Association :> Normal[a],
 q_Quantity :> QuantityMagnitude[q],
 d_DateObject :> d@"Year",
 g_GeoPosition :> {Latitude[g], Longitude[g]}
}, "JSON"] &]

What it does is to convert the Dataset into a list of rules using Normal (as ExportString[_,"JSON"] can not directly digest the Dataset). It then converts all elements that can not directly be exported to something equivalent that can be exported. Check the documentation for more details about the various data types and functions used.

As you seem to have problems to get the APIFunction to work, here is example code which shows how to deploy the APIFunction:

co = CloudDeploy[api, Permissions -> "Public"];

... check that it works correctly (note that you need to include the space in "tablename" and URL-encode it, which URLBuild will conveniently do for you):

Import[URLBuild[co, {"tablename" -> "Meteorite Landings"}], "RawJSON"]

... and finally remove the public api (you probably don't want it to linger around and let others consume your cloud credits):

DeleteFile[co]

One more tip when working with such code: I would only deploy some functionality to the cloud once it works locally. In your case you could for example test the conversion to JSON entirely on your local machine without spending any cloud credits and resulting an a much faster loop while developing/testing:

data = ResourceData[ResourceObject["Meteorite Landings"]]

Length[data]

Take[data, 10]

ExportString[(Take[data, 10] // Normal) //. {a_Association :> 
  Normal[a], q_Quantity :> QuantityMagnitude[q], 
  d_DateObject :> d@"Year", 
  g_GeoPosition :> {Latitude[g], Longitude[g]}}, "JSON"]

What you are getting is not "CDF format" but a Mathematica Dataset. You should also note that you are trying to convert and serve a dataset that has 45716 entries. This might well run into limits (cputime, memory, transfered data) of an APIFunction. I am also not sure whether WRI will allow you to provide a possibility to download complete resource-data datasets, you would have to check their legal conditions. Finally you should note that there is already a possibility to download the whole dataset from https://datarepository.wolframcloud.com/resources/Meteorite-Landings, although the JSON that is delivered looks a bit special (it is a Mathematica expression expressed as JSON arrays, probably not what one would expect...).

Using the following code in your API function should convert the first 10 entries into a JSON equivalent of the Dataset:

api=APIFunction[{"tablename" -> "String"},ExportString[
 (Take[ResourceData[ResourceObject[#tablename]],10] // Normal) //. {
 a_Association :> Normal[a],
 q_Quantity :> QuantityMagnitude[q],
 d_DateObject :> d@"Year",
 g_GeoPosition :> {Latitude[g], Longitude[g]}
}, "JSON"] &]

What it does is to convert the Dataset into a list of rules using Normal (as ExportString[_,"JSON"] can not directly digest the Dataset). It then converts all elements that can not directly be exported to something equivalent that can be exported. Check the documentation for more details about the various data types and functions used.

As you seem to have problems to get the APIFunction to work, here is example code which shows how to deploy the APIFunction:

co = CloudDeploy[api, Permissions -> "Public"];

... check that it works correctly (note that you need to include the space in "tablename" and URL-encode it, which URLBuild will conveniently do for you):

Import[URLBuild[co, {"tablename" -> "Meteorite Landings"}], "RawJSON"]

... and finally remove the public api (you probably don't want it to linger around and let others consume your cloud credits):

DeleteFile[co]

What you are getting is not "CDF format" but a Mathematica Dataset. You should also note that you are trying to convert and serve a dataset that has 45716 entries. This might well run into limits (cputime, memory, transfered data) of an APIFunction. I am also not sure whether WRI will allow you to provide a possibility to download complete resource-data datasets, you would have to check their legal conditions. Finally you should note that there is already a possibility to download the whole dataset from https://datarepository.wolframcloud.com/resources/Meteorite-Landings, although the JSON that is delivered looks a bit special (it is a Mathematica expression expressed as JSON arrays, probably not what one would expect...).

Using the following code in your API function should convert the first 10 entries into a JSON equivalent of the Dataset:

api=APIFunction[{"tablename" -> "String"},ExportString[
 (Take[ResourceData[ResourceObject[#tablename]],10] // Normal) //. {
 a_Association :> Normal[a],
 q_Quantity :> QuantityMagnitude[q],
 d_DateObject :> d@"Year",
 g_GeoPosition :> {Latitude[g], Longitude[g]}
}, "JSON"] &]

What it does is to convert the Dataset into a list of rules using Normal (as ExportString[_,"JSON"] can not directly digest the Dataset). It then converts all elements that can not directly be exported to something equivalent that can be exported. Check the documentation for more details about the various data types and functions used.

As you seem to have problems to get the APIFunction to work, here is example code which shows how to deploy the APIFunction:

co = CloudDeploy[api, Permissions -> "Public"];

... check that it works correctly (note that you need to include the space in "tablename" and URL-encode it, which URLBuild will conveniently do for you):

Import[URLBuild[co, {"tablename" -> "Meteorite Landings"}], "RawJSON"]

... and finally remove the public api (you probably don't want it to linger around and let others consume your cloud credits):

DeleteFile[co]

One more tip when working with such code: I would only deploy some functionality to the cloud once it works locally. In your case you could for example test the conversion to JSON entirely on your local machine without spending any cloud credits and resulting an a much faster loop while developing/testing:

data = ResourceData[ResourceObject["Meteorite Landings"]]

Length[data]

Take[data, 10]

ExportString[(Take[data, 10] // Normal) //. {a_Association :> 
  Normal[a], q_Quantity :> QuantityMagnitude[q], 
  d_DateObject :> d@"Year", 
  g_GeoPosition :> {Latitude[g], Longitude[g]}}, "JSON"]
2 added 1317 characters in body
source | link
1
source | link