Reputation: 21
My goal is to to be able to produce a csv file. For now just trying to return a list of ids in JSON.
I'm struggling to map a response, so my JSON is:
{
"items": [
{
"id": "2017-07-02_n_Eleana Qorgyle",
"groupId": "n_2017-07"}
]
}
and my model is
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Log",
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "string" }
}
}
}
}
}
My Velocity template is ...
#set($inputRoot = $input.path('$'))
{
"items" : [
##TODO: Update this foreach loop to reference array from input json
#foreach($elem in $inputRoot.items)
{
"id" : "foo"
}
#if($foreach.hasNext),#end
#end
]
}
However, I am getting this output:
{
"items": []
}
Have I missed something? $inputRoot.body outputs everything, but iterating is an issue.
Upvotes: 2
Views: 941
Reputation: 141
I think this is what you are trying to do:
#set($inputRoot = $input.path('$')) {
"items" : [
#foreach($elem in $inputRoot.items){
"id" : "$elem.get('id')"
}
#if($foreach.hasNext),#end
#end
]
}
Thanks!
Upvotes: 2