# Package my output in as a json?

**URL:** <https://community.wolfram.com/t/package-my-output-in-as-a-json/15314>\
**Category:** Questions\
**Tags:** data-science, software-development, mathematica, external-interfaces, import-and-export\
**Created:** [January 29, 2020, 3:40pm UTC](https://community.wolfram.com/t/package-my-output-in-as-a-json/15314 "2020-01-29T15:40:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdelamotasanchis](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jdelamotasanchis](https://community.wolfram.com/u/jdelamotasanchis)\
**Post date:** [January 29, 2020, 3:40pm UTC](https://community.wolfram.com/t/package-my-output-in-as-a-json/15314/1 "2020-01-29T15:40:55Z")

</div>

Hello everyone.  
I have constructed a program which provides an output as a .txt. I have to email this output and the reciever has requested me to send it as a .json instead. I have attempted to simply save the output replacing .txt by .json using export as.

```
Export["savedWindXPythonJ.json", savedXPython];

```

However, I recive an error message Export::badval: The element Data contains invalid values.

Is there a way to save the variable to a json any answer is appreciated?  
I will attach the .txt version.

Regards.

Jaime.

[savedWindXPython.txt](https://community.wolfram.com/uploads/short-url/xecfMmHfVIxHMDNx8DeaKHc9vmb.txt) (521 Bytes)

---

<div class="post-metadata">

**Author:** ![gdelfino](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/gdelfino/32/41294_2.png) [@gdelfino](https://community.wolfram.com/u/gdelfino)\
**Post date:** [January 29, 2020, 7:00pm UTC](https://community.wolfram.com/t/package-my-output-in-as-a-json/15314/2 "2020-01-29T19:00:44Z")

</div>

You can export a list of rules or an association to JSON, but what you have is a different Mathematica expression (a long formula). Any Mathematica expression can be converted to JSON using the “ExpressionJSON” format:

```
Export["savedWindXPythonJ.json", savedXPython,"ExpressionJSON"];

```

I use this to save Mathematica expressions into a JSON based database.

UPDATE: I just noticed that your formula is not even a Mathematica expression. So I don’t know what you are trying to do.

---

<div class="post-metadata">

**Author:** ![jdelamotasanchis](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jdelamotasanchis](https://community.wolfram.com/u/jdelamotasanchis)\
**Post date:** [January 30, 2020, 11:24am UTC](https://community.wolfram.com/t/package-my-output-in-as-a-json/15314/3 "2020-01-30T11:24:27Z")

</div>

Hello Gustavo.

First of all, thanks for your answer.

I am trying to send a mathematical expression readable by pyomo to another person. I have constructed it in Mathematica and then adapted it to Python’s grammar as

```
savedXPython = 
 Import["savedWindX.txt"] // 
  StringReplace[#, {"[" -> "(", "]" -> ")", 
     "t" -> "m.lammda[i]*180/np.pi", "u" -> "m.phi[i]*180/np.pi"}] &

```

Since I want this to be executed without having to do any work on the file.  
I have sent it as a txt but it seems that that is causing trouble.  
That is why I am trying to convert the expression to a way that can be read using pyomo.

Regards.  
Jaime.
