I have a library of FAQs that are split up into tabs on the front end, we have since built a NodeJS app that handles them so we can have a database of FAQs instead of hardcoded HTML.
I have a NodeJS model generating a JSON file that is filtering the questions by their tab association using the following:
res = _.groupBy(res, 'tab_title');
Which is outputting this.
However, below is the structure of the original JSON file that the Mustache tags in the template are expecting it to look like:
{
"tabs": [
{
"title": "Tab title",
"id": 1,
"questions": [
{
"question": "Question here",
"id": 1,
"answer": "Answer here"
},
{
"question": "Question two",
"id": 2,
"answer": "Answer here"
}
]
},
{
"title": "Another title",
"id": 2,
"questions": [
{
"question": "Question here",
"id": 1,
"answer": "Answer here"
},
{
"question": "Question two",
"id": 2,
"answer": "Answer here"
}
]
}
}
This is so the front end tags can just loop over the tabs, then loop over the questions within the tabs so the front end is relatively automated.
I have tried to use the _.map function to output all the appropriate information in this structure but I'm really struggling. Can anyone point my in a direction that could help?
I hope this is enough information, but if not, I can supply more.
Thanks!
So we start by generating the groups like you did.
_.groupBy(myArray, 'tab_title');
However, that doesn't quite solve our issue here, the object still wont match the intended structure. It'll look like :
{
"tab_title1" : [{...}, {...}],
"tab_title2" : [{...}, {...}]
}
So we could use the map function to process this further :
_.map(groupObject, (lstFaqs, tab_title) => {
let first = _.first(lstFaqs),
tab_object = {
title: first.tab_title,
id: first.tab_id,
questions: _.map(lstFaqs, (faqItem) => {
id: faqItem.faq_id,
question : faqItem.faq_question,
answer : faqItem.faq_answer
})
}
return tab_object;
})
We'll end up with an array of tab_object. So to finalize the formatting :
let result = { "tabs" : array_of_tab_object }
I hope this help!
Related
So far I manage to create the Test issue, but I can't find the correct JSON structure to populate the field:
customfield_11101 , name: Zephyr Teststep , required: false , type: any
I would like to be able to do something like this:
var issueTest = {
"fields": {
"issuetype": {
"name": "Test"
},
"project":
{
"key": "STORYKEY"
},
"summary": "Navigate to a Different Region",
"description": "",
"assignee": {
"name": "someemail#email.com"
},
"customfield_10014": "SOMEKEY",
"duedate": "2018-10-03",
"priority": {
"name": "Blocker"
},
"labels": ["label1", "label2"],
"customfield_19416": "50h",
"customfield_19719": {
"value": "minor"
},
"customfield_11101": [
{
"Test Step": "some text",
"Test Data": "some text",
"Test Result": "some text"
},
{
"Test Step": "some text",
"Test Data": "some text",
"Test Result": "some text"
},
{
"Test Step": "some text",
"Test Data": "some text",
"Test Result": "some text"
}
]
}
};
I'm not completely familiar with the Zephyr fields but have you tried something like this:
"fields": {
//other field data
"customfield_11101": {
"value": //put your array here
}
}
If that doesn't work then find another issue in your JIRA instance that has that field filled out and query it through the API, you can then see what the structure of that field's value should be
Thirdly, if all else fails, Zephyr has their own API which you can probably use to make the changes you need. There's a separate TeststepResource endpoint even.
First I want the thanks #rorschach, his answer help me a lot.
I find a way. it is not ideal but works
The idea is create the Test and use the new Test id to create the related steps using this (suggested by #rorschach):
http://docs.getzephyr.apiary.io/#reference/teststepresource/create-get-list-of-teststeps/create-new-teststep
I have a deeply nested document(pseudo structure as shown below):
[{
"id": "1",
"company_id": "1",
"company_name": "company_1",
"departments":[{
"dep1" : [{
"id" : 40,
"name" : xyz
},
{
"id" : 41,
"name" : xyr
}],
"dep2": [{
}]
}]
"employeePrograms" :[{
}]
}]
How can I index these type of documents in Apache Solr?
Documentation gives the idea of immediate child documents alone.
Unfortunatelly i'm don't have huge experience with this technology, but want to help. Here is some official documentation, that might be useful: oficial doc
more specific
If you have some uncommon issue, tell about it, maybe any error, or whatever.. I would try my best to help)
Upd1 :
Solr can only maintain a 'flat' representation of the data. What you weretrying to do is not really possible. There are a number of workarounds, such as using dynamic fields and using a solr join to link multiple data sets.
Speking about a deep nesting ? I've found such an example of work around.
If you had something like that:
"docs": [
{
"name": "Product Name",
"categories": [
{
"name": "Category 1",
"priority": 8
},
{
"name": "Category 2",
"priority": 6
}
...
]
},
You have to modify it like that to make it not deeply nested :
"docs": [
{
name: "Sample Product"
categories: [
{
priority_category: "9_Category 1",
},
{
priority_category: "5_Category 2",
}
...
]
},
So, you've done something similar, check if there are any errors anywhere
Forgive me if this is a newbie question. I'm very new to Angular.
I've looked everywhere for this, and while there are a lot of questions answered about setting a default selected option, I haven't found one where the selected option is set dynamically from values in a JSON file.
My controller looks like this:
peopleControllers.controller('PeopleListCtrl', ['$scope','PeopleList',
function($scope, PeopleList) {
$scope.id = 'id';
$scope.people = PeopleList.query();
$scope.orderProp = 'name';
$scope.comments = 'comments';
$scope.department = 'department';
$scope.departmentList = [
{id : 1, name : "HR" },
{id : 2, name : "Accounting"},
{id : 3, name : "Marketing"}
];
}]);
PeopleList is a $resource that comes from a JSON file formatted like this:
[
{
"id": "johnasmith",
"name": "John A. Smith",
"department": "1",
"comments": "Good worker"
},
{
"id": "sarahqpublic",
"name": "Sarah Q. Public",
"department": "2",
"comments": "New hire"
},
{
"id": "janedoe",
"name": "Jane Doe",
"department": "3",
"comments": "Good resource for information"
}
]
...
And in the HTML, I have this:
ul class="people">
<li ng-repeat="person in people | filter:query | orderBy:orderProp">
<h3>{{people.name}}</h3>
<p>{{people.comments}}</p>
<select ng-model="department" ng-options="departmentList.name for department in departmentList track by department.id">
</select>
</li>
</ul>
The select statement populates with all the right info from departmentList, but its selected value ends up being blank. If I set a static value for $scope.department, like $scope.department = $scope.departmentList[1]; (for "Accounting") it works perfectly. But it doesn't seem to be able to pull the department value from the JSON file.
I know I'm missing something simple and obvious. There have got to be other people who have already asked and had answered this question, so I'm sorry if this turns out to be a duplicate. But I'm really stymied right now.
From Docs
select as and track by Do not use select as and track by in the same
expression. They are not designed to work together.
Additionally as #Chrillewoodz suggested you need to convert the string to number for department id
Markup
<select ng-model="person.department"
ng-options="department.id as department.name for department in departmentList">
</select>
Demo Plunkr
You JSON file contains only strings which is causing you to search for the value "3" in the array instead of selecting [3]. So change your JSON to department: 3 instead of department: "3" and so on.
Like this:
{
"id": "johnasmith",
"name": "John A. Smith",
"department": 1,
"comments": "Good worker"
},
{
"id": "sarahqpublic",
"name": "Sarah Q. Public",
"department": 2,
"comments": "New hire"
},
{
"id": "janedoe",
"name": "Jane Doe",
"department": 3,
"comments": "Good resource for information"
}
Also you should do select ng-model="person.department".
I have a large JSON file that I'm trying to parse with JSON Slurper. The JSON file consists of information about bugs so it has things like issue keys, descriptions, and comments. Not every issue has a comment though. For example, here is a sample of what the JSON input looks like:
{
"projects": [
{
"name": "Test Project",
"key": "TEST",
"issues": [
{
"key": "BUG-1",
"priority": "Major",
"comments": [
{
"author": "a1",
"created": "d1",
"body": "comment 1"
},
{
"author": "a2",
"created": "d2",
"body": "comment 2"
}
]
},
{
"key": "BUG-2",
"priority": "Major"
},
{
"key": "BUG-3",
"priority": "Major",
"comments": [
{
"author": "a3",
"created": "d3",
"body": "comment 3"
}
]
}
]
}
]
}
I have a method that creates Issue objects based on the JSON parse. Everything works well when every issue has at least one comment, but, once an issue comes up that has no comments, the rest of the issues get the wrong comments. I am currently looping through the JSON file based on the total number of issues and then looking for comments using how far along in the number of issues I've gotten. So, for example,
parsedData.issues.comments.body[0][0][0]
returns "comment 1". However,
parsedData.issues.comments.body[0][1][0]
returns "comment 3", which is incorrect. Is there a way I can see if a particular issue has any comments? I'd rather not have to edit the JSON file to add empty comment fields, but would that even help?
You can do this:
parsedData.issues.comments.collect { it?.body ?: [] }
So it checks for a body and if none exists, returns an empty list
UPDATE
Based on the update to the question, you can do:
parsedData.projects.collectMany { it.issues.comments.collect { it?.body ?: [] } }
I'm requesting packets from a Server that I have no control over and they have no interest in any issues developers might have.
I would love to use the built in json_decode for PHP because of the speed, but I'm using a PHP based decoder from http://mike.teczno.com/json.html, and it can be extremely slow on packets with 40,000+ records.
This is the JSON after I've received it from the server and stripped the slashes (stripslashes()):
{
"results": {
"localPlayers": {
"friends": [
{
"name": "Player Name 1",
"friend_name": "Friend Name 1",
"level": "3"
},
{
"name": ""PlayerName2"",
"friend_name": "",
"level": "3"
},
{
"name": "Pl/\yer Name 3",
"friend_name": "Friend Name 3",
"level": "3"
},
{
"name": "Player Name 4",
"friend_name": "Friend "Name4"",
"level": "4"
}
]
}
}
}
It should be:
{
"results": {
"localPlayers": {
"friends": [
{
"name": "Player Name 1",
"friend_name": "Friend Name 1",
"level": "3"
},
{
"name": "\"PlayerName2\"",
"friend_name": "",
"level": "3"
},
{
"name": "Pl/\\yer Name 3",
"friend_name": "Friend Name 3",
"level": "3"
},
{
"name": "Player Name 4",
"friend_name": "Friend \"Name4\"",
"level": "4"
}
]
}
}
}
I've tried different things and searched all over for an alternate PHP extension that might handle "lazy" JSON. I think I've melted my brain by looking at all of the JSON offspring that are out there (in case this was normal to one or another), but can't seem to find anything that fits.
It would be nice to not have to hand edit the packets and use the speed of the built in PHP json decoder, but getting accurate info is more important and utilizing the Services_JSON has been my only answer.
Also, is the reason that Services_JSON is able to decode due to a bug in that decoder or in the JSON produced?
I'm hoping someone sees these "malformed" JSON packets and recognizes them.
Thank you.
Edit:
My apologies, here is the packet from the server before stripslashes:
I was using the stripslashes originally for the Apostrophes. :(
{
"results":{
"localPlayers":{
"friends":[
{
"name":"Player\'s Name 1",
"friend_name":"Friend Name 1",
"level":"3"
},
{
"name":""PlayerName2"",
"friend_name":"",
"level":"3"
},
{
"name":"Pl/\yer Name 3",
"friend_name":"Friend Name 3",
"level":"3"
},
{
"name":"Player Name 4",
"friend_name":"Friend "Name4"",
"level":"4"
}
]
}
}
}
Can you check if you are not using functions in any form in your code
stripslashes()
str_replace()
Check if you can use [JSON_UNESCAPED_SLASHES()][1] Available since PHP 5.4
In php.ini set magic_quotes_gpc = Off but this feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.