Closed mabouza closed 8 years ago
Is there any work being done on this one, or is there a workaround to get json formatted as an array?
@bradrice it works with some JSON but JSON formatted with the example above doesn't work for the array. We will pick off eventually but haven't yet
Unfortunately, that is the format of the json I need to pull in.
On Tue, Apr 23, 2013 at 12:22 PM, Jason Tesser notifications@github.comwrote:
@bradrice https://github.com/bradrice it works with some JSON but JSON formatted with the example above doesn't work for the array. We will pick off eventually but haven't yet
— Reply to this email directly or view it on GitHubhttps://github.com/dotCMS/dotCMS/issues/1991#issuecomment-16869026 .
Brad Rice bradrice1@gmail.com ~ “God has promised pardon to your conversion; He has not promised a tomorrow to your delay.” - Augustine
@bradrice @mabouza using the following code
#set($fArray = $json.fetch("http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=yahoo&callback=YAHOO.Finance.SymbolSuggest.ssCallback").ResultSet.Result)
#foreach( $product in $fArray )
$product.symbol
#end
ResultSet :
Query : Yahoo
Result : [
Symbol: value, name: value, exch: value, type: value, . . . .,
Symbol: value, name: value, exch: value, type: value, . . . .,
Symbol: value, name: value, exch: value, type: value, . . . .,
Symbol: value, name: value, exch: value, type: value, . . . .
]
In order to fetch the array elements from the above JSON Object,
we need to dig into JSONObject -> ResultSet -> Result -> ArrayElement
that isn't the format that I was having trouble with. Mine was a top level array.
This is the format I only get the first result from fetch: https://gist.github.com/bradrice/21b9eea4916c6ed409f1
@bradrice You'll have to provide a URL with an example that fails.
Here is the page using that sample array I showed you in the gist.
http://www.uakron.edu/test/test-json.dot
Here is the code on that page:
<!doctype html>
Array: $fArray
Sorry, that code didn't show correctly. Here is s a gist with my code: https://gist.github.com/bradrice/fb4e064ec60b6d03d77b
The json is here: http://www.uakron.edu/test/test.json
I used jsonlint.org to validate my json.
I noticed, I am not the only one who has noticed this bug:
Confirmed that this format of JSON does not work with the json tool. A workaround:
So I think the json tool expects things to start with objects. You should be able to do a read first and then surround it, something like:
#set($jsonData = $import.read("http://www.uakron.edu/test/test.json"))
#set($jsonData = "{data:${jsonData}}")
#set($jsonObject = $json.generate($jsonData))
#foreach($item in $jsonObject.data)
$item.id - $item.title <br />
#end
Thanks
Yes, but it would be nice if it just worked right.
On Wed, Jan 15, 2014 at 10:54 AM, Christopher Falzone < notifications@github.com> wrote:
Confirmed that this format of JSON does not work with the json tool. A workaround:
So I think the json tool expects things to start with objects. You should be able to do a read first and then surround it, something like:
set($jsonData = $import.read("http://www.uakron.edu/test/test.json"))
set($jsonData = "{data:${jsonData}}")
set($jsonObject = $json.generate($jsonData))
foreach($item in $jsonObject.data)
$item.id - $item.title
end
— Reply to this email directly or view it on GitHubhttps://github.com/dotCMS/dotCMS/issues/1991#issuecomment-32374046 .
Brad Rice
“Be curious. Read widely. Try new things. What people call intelligence just boils down to curiosity.”
Hey Shay, I just tested using this example that Will gave me... working
https://gist.github.com/DeanGonzalez/721b6aadcf23ca85f31603bd443836b3
We need to test that our non-array json pulls still work as well.
Tested and see John already documented here during 3.3 release: http://authoring.dotcms.com/docs/latest/jsontool#Iteration
Passed QA. Array and non-array json pulls are working. Tool allows to pass headers Tested locally in master-3.6 // Mac OS 10.10 // MySQL 5.6.23 // Firefox
The JSONTool that ships with dotCMS is not able to deal with JSON arrays, e.g.
You have to wrap the list as a json property in the string which is clunky. Reason is that JSON arrays are not really valid json objects and fail json validation, .e.g. jsonlint.com, but the fact is most everyone is returning them via their web services and so we should handle.
Additionally, it would be very nice if we could provide a way for users to pass Headers to allow for basic auth and other header properties to the tool.