DataGraph Forums › Technical Support › Support Desk › What is wrong with this JSON, or with me?
Tagged: json
DataGraph refuses to show me any data when I try to link to a file containing this:
{“success”:true,”base”:”USD”,”timestamp”:1725407999,”rates”:{“EUR”:0.9036476597,”USDEUR”:1.1066260055,”USDXAG”:28.5453737408,”USDXAU”:2496.4263656576,”XAG”:0.0350319463,”XAU”:0.0004005726}}
Show response looks sensible. I would be tearing my hair out if I had any.
We tried this text as is and one issue seems to be the use of smart quotes. When we stripped those out, DataGraph would read the file, but this format is not what we implemented to read. DataGraph will work with an array of dictionaries, where each dictionary is a key value pair.
Here is an example of the data in a format that works.
[{“Curr”:”EUR”,”Val”:0.9036476597},
{“Curr”:”USDEUR”,”Val”:1.1066260055},
{“Curr”:”USDXAG”,”Val”:28.5453737408},
{“Curr”:”USDXAU”,”Val”:2496.4263656576},
{“Curr”:”XAG”,”Val”:0.0350319463},
{“Curr”:”XAU”,”Val”:0.0004005726}]
Here is the corresponding response from DataGraph:
The JSON importer should also ignore a header line, but currently, the data has to be in this format.
There are some examples here on this webpage that may be helpful.
Hope this helps!
My objective in asking this was to try to use datagraph instead of Excel for retrieving some data.
The “smart” quotes came from a copy/ paste into the post. I had the same problem when I copy/ pasted your example data into a vi session ;).
Can I take it the JSON parser wants an array of at least two dictionaries? Because here’s another example of some JSON that will not be parsed, and I do not think there are any smart quotes in sight (c.f. the od -c output at the bottom). Thus, the JSON parser can’t handle a trivial case of one returned, non-nested JSON object?
At the moment it seems I can’t simply run curl to collect these JSON data without inserting an extra step to artificially process the JSON into a form datagraph will accept.
I can’t attach files to posts so any “smart”, invisible data mangling is difficult to eliminate. All values have a key and there is only one { object }, no arrays or whatever the JSON term for [ … ] is. After this, I have added two simple JSON snippets. The first isn’t parsed and the second is parsed.
% curl -Ss -X GET ‘https://www.goldapi.io/api/XAU/USD’ -H ‘x-access-token: goldapi-XXXXXXXXXXXXXXXX-io’ | json_pp | tee gold-spot-goldapi.io.json
{
“ask” : 2576.3,
“bid” : 2575.54,
“ch” : -6.58,
“chp” : -0.25,
“currency” : “USD”,
“exchange” : “FOREXCOM”,
“high_price” : 2586.39,
“low_price” : 2574.645,
“metal” : “XAU”,
“open_price” : 2582.49,
“open_time” : 1726531200,
“prev_close_price” : 2582.49,
“price” : 2575.905,
“price_gram_10k” : 34.5072,
“price_gram_14k” : 48.3101,
“price_gram_16k” : 55.2115,
“price_gram_18k” : 62.113,
“price_gram_20k” : 69.0144,
“price_gram_21k” : 72.4651,
“price_gram_22k” : 75.9158,
“price_gram_24k” : 82.8173,
“symbol” : “FOREXCOM:XAUUSD”,
“timestamp” : 1726550769
}
% od -c gold-spot-goldapi.io.json
0000000 { \n ” a s k ” : 2 5 7
0000020 6 . 3 , \n ” b i d ” :
0000040 2 5 7 5 . 5 4 , \n ” c h ”
0000060 : – 6 . 5 8 , \n ” c h
0000100 p ” : – 0 . 2 5 , \n ”
0000120 c u r r e n c y ” : ” U S D
0000140 ” , \n ” e x c h a n g e ”
0000160 : ” F O R E X C O M ” , \n
0000200 ” h i g h _ p r i c e ” :
0000220 2 5 8 6 . 3 9 , \n ” l o
0000240 w _ p r i c e ” : 2 5 7 4 .
0000260 6 4 5 , \n ” m e t a l ”
0000300 : ” X A U ” , \n ” o p e
0000320 n _ p r i c e ” : 2 5 8 2 .
0000340 4 9 , \n ” o p e n _ t i m
0000360 e ” : 1 7 2 6 5 3 1 2 0 0 ,
0000400 \n ” p r e v _ c l o s e _
0000420 p r i c e ” : 2 5 8 2 . 4 9
0000440 , \n ” p r i c e ” : 2
0000460 5 7 5 . 9 0 5 , \n ” p r i
0000500 c e _ g r a m _ 1 0 k ” : 3
0000520 4 . 5 0 7 2 , \n ” p r i c
0000540 e _ g r a m _ 1 4 k ” : 4 8
0000560 . 3 1 0 1 , \n ” p r i c e
0000600 _ g r a m _ 1 6 k ” : 5 5 .
0000620 2 1 1 5 , \n ” p r i c e _
0000640 g r a m _ 1 8 k ” : 6 2 . 1
0000660 1 3 , \n ” p r i c e _ g r
0000700 a m _ 2 0 k ” : 6 9 . 0 1 4
0000720 4 , \n ” p r i c e _ g r a
0000740 m _ 2 1 k ” : 7 2 . 4 6 5 1
0000760 , \n ” p r i c e _ g r a m
0001000 _ 2 2 k ” : 7 5 . 9 1 5 8 ,
0001020 \n ” p r i c e _ g r a m _
0001040 2 4 k ” : 8 2 . 8 1 7 3 , \n
0001060 ” s y m b o l ” : ” F
0001100 O R E X C O M : X A U U S D ” ,
0001120 \n ” t i m e s t a m p ”
0001140 : 1 7 2 6 5 5 0 7 6 9 \n } \n
0001157
This JSON is not parsed by datagraph (no smart quotes)
[{“Curr”:”EUR”,”Val”:0.9036476597}]
This is parsed (no smart quotes)
[{“Curr”:”EUR”,”Val”:0.9036476597},
{“Curr”:”THB”,”Val”:0.9036476597}]
DataGraph Forums › Technical Support › Support Desk › What is wrong with this JSON, or with me?