Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Convert data into a JSON-compatible form
ResourceFunction["EnsureJSON"][data] gives a JSON-compatible conversion of data. | |
ResourceFunction["EnsureJSON"][data,prop] returns the specified property prop. |
"Raw" | (default) list of rules compatible with JSON export |
"JSON" | JSON string |
"CompactJSON" | JSON string with whitespace removed |
ExportForm | ExportForm expression |
HTTPResponse | HTTPResponse object |
Convert a list of rules containing DateObject values to a JSON-compatible form:
In[1]:= |
![]() |
Out[1]= |
![]() |
Convert a nested Association containing Quantity expressions:
In[2]:= |
![]() |
Out[2]= |
![]() |
Convert data with Entity objects to a JSON-compatible form:
In[3]:= |
![]() |
Out[3]= |
![]() |
Export the data to JSON directly:
In[4]:= |
![]() |
Out[4]= |
![]() |
Use a more compact JSON formatting:
In[5]:= |
![]() |
Out[5]= |
![]() |
Create an ExportForm expression:
In[6]:= |
![]() |
Out[6]= |
![]() |
Deploy it to the cloud to create an active webpage:
In[7]:= |
![]() |
Out[7]= |
![]() |
Create an HTTPResponse object:
In[8]:= |
![]() |
Out[8]= |
![]() |
Deploy the http response to the cloud to make a live API:
In[9]:= |
![]() |
Out[9]= |
![]() |
Use the API:
In[10]:= |
![]() |
Out[10]= |
![]() |
Include additional custom rules in the conversion by using the AdditionalRules option:
In[11]:= |
![]() |
Out[11]= |
![]() |
Rules given in "AdditionalRules" are applied before the standard conversion rules:
In[12]:= |
![]() |
Out[12]= |
![]() |
In[13]:= |
![]() |
Out[13]= |
![]() |
Some expressions are not readily converted to JSON-compatible forms. EnsureJSON removes those values from the data:
In[14]:= |
![]() |
Out[14]= |
![]() |
Non-string keys are also removed:
In[15]:= |
![]() |
Out[15]= |
![]() |
Define data containing many values that do not usually convert to JSON:
In[16]:= |
![]() |
Out[16]= |
![]() |
Exporting fails:
In[17]:= |
![]() |
Out[17]= |
![]() |
EnsureJSON works:
In[18]:= |
![]() |
Out[18]= |
![]() |
The data should have a structure compatible with JSON:
In[19]:= |
![]() |
Out[19]= |
![]() |
Use lists of rules instead of unwrapped expressions:
In[20]:= |
![]() |
Out[20]= |
![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License