# Tag Info

17

Here's a set of functions that allows to do this. The code uses many ideas found on this site and on other places on the web. It is a bit factorized already so it should be easily reusable. More on YQL and available tables here: https://developer.yahoo.com/yql https://github.com/yql Query test Edit: this API is great also and simple ...

17

I separated this project into two parts. The first is to compute the coordinates of the Geohash location. (*Grab the user's geographical location. The location is based on IP address, so it may not be completely accurate. It's usually good enough to get your graticute. You can replace home with with known coordinates in the form {hx, hy} if you like.*) home ...

14

It seems to me that this is the correct way to extract values from a nested list of rules: Data ad = {"accept_rate" -> 75, "account_id" -> 395497, "age" -> 41, "badge_counts" -> {"bronze" -> 35, "gold" -> 0, "silver" -> 11}, "creation_date" -> 1326833982, "display_name" -> "Verbeia", "is_employee" -> False, ...

12

The bug is in the SystemConvertJSONDumptoString[] function which is defined like this: toString[num_?NumberQ, t_Integer] := If[Head[num] === Real && IntegerPart[num] == num, ToString[CForm[N[num]]] ~~ "0", ToString[CForm[N[num]]]] If my guess is correct, the purpose of the ~~ "0" part is to change 1. to 1.0. I am not very familiar with ...

10

I ran into the same issue. Dataset and nested Associations have a structure ideally suited for JSON export, but the JSON exporter only supports lists of rules. Any other type of expression triggers the error you see. Export The workaround is to recursively convert all nested associations to lists of rules. normalAsc[expr_] := expr //. a_Association ...

9

It is possible to get rid of all but one ReplaceAll. First, you need to remember that ReplaceAll tests each Rule in order, so to deal with the missing "badge_counts" condition, you can simply add that to the list, as follows {"display_name", "creation_date", "reputation", "reputation_change_week", "is_employee", "last_access_date", "user_type", ...

8

See Szabolcs answer for the explanation. The number form there needs to be corrected because JSON needs a digit between . and e: Therefore, here the solution: SystemConvertJSONDumptoString[num_?NumberQ, t_Integer] := StringReplace[ToString[CForm[N[num]]], RegularExpression["\\.(($)|(e))"] -> ".0$1"]; For the following input: ...

7

You can define your own object and tell Mathematica to interpret it as JSON object. Dummy export to load relevant contexts: In[1]:= ExportString["", "JSON"]; Tell Mathematica to interpret JSONObject symbol as possible head of JSON objects: In[2]:= ClearAll[JSONObject] SystemConvertJSONDump\$JSONObjectHead = JSONObject; Now you can use ...

7

Element as referred to in the documentation are not a JSON elements, but the kind of information you can get from the specified file format. For JSON the elements available is just Data as given by Import["out.json", "Elements"]. For a typical JPEG photo the available elements are: {"Aperture", "BitDepth", "CameraTopOrientation", "ColorMap", \ ...

7

The reason is that the JSON format is quite limited. It doesn't support arbitrary expressions. You can e.g. see that by trying the folllowing: Export["test.json",someSymbol,"JSON"] You'll get the same error. If your goal is just to pass the expressions around (i.e. on the other side is another Mathematica instance to interpret them), the simplest ...

6

The short answer is that, as @FJRA noted in the comment, only certain types are supported. Which types? Enter the long answer. Why the converter behaves as it does Long answer: JSON supports only certain types, and their nested combinations, as defined e.g. here. Mathematica converter maps JSON objects to lists of rules, arrays to lists, strings to ...

5

This seems to be a Java heap space error. I encounter this quite often when importing large Excel sheets, though I get a different error message: Import::nojmem. The help page for this error contains instructions that may be useful for you as well. Basically, you increase heap space using the following commands: Needs["JLink"] ReinstallJava[JVMArguments ...

2

Perhaps this might work to add the zeros after the decimal point: SystemConvertJSONDump`toString[num_?NumberQ,t_Integer]:= StringReplace[ StringReplace[ ToString[CForm[N[num]]], RegularExpression["\\.&"]->".0" ], ".e"->".0e" ] I cannot check, but this seems to comply with the format descriptions provided by hwlau.

1

Longtime user, first time responder. I am going to assume that by parsing you mean extracting values from JSON data and not transforming data into JSON. There are a couple ways to parse JSON in Mathematica. Assuming the data is already a set of rules in Mathematica using Import[data, "JSON"] or something like that. data = {blah -> blah, field1 ...

Only top voted, non community-wiki answers of a minimum length are eligible