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.
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 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!
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
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 ?: [] } }
prodCollect.fetch({
success: function(collection){
console.log(prodCollect.models.length);
var a =prodCollect.models[1];
console.log(a.attributes);
var y=_(a.attributes).toArray();
console.log(y[0]);
}
});
In variable 'a', I'm getting a model and doing console(a.attributes), I'm getting this:
Object {[{"product_id":"2","product_name":"new product","short_description":"used for training of managers","full_description":"used for training of managers","price":"20000.00","acct_manager":"rahul raja","roles":"Manager,Manager","tags":"abc,def","skills":"abc,abc","clients":"accenture,accenture,Wipro,Google"}]: Object}
Now I am unable to access the properties like 'product_name' and 'price'. I tried converting a.attributes into an array and accessing y[0] but its undefined. 'a.attributes' is an object. So I am unable to access the properties.
I am sending this from server
[
"[{\"program_name\":\"training\",\"products\":\"new product,fdgf\",\"roles\":\"Manager,CEO,random\",\"tags\":\"abc,def\",\"skills\":\"abc,def\",\"clients\":\"accenture,wipro\"},{\"program_name\":\"New progs\",\"products\":\"fdgf,ILead\",\"roles\":\"CEO,Manager,random\",\"tags\":\"abc,def\",\"skills\":\"abc,def\",\"clients\":\"\"}]",
"[{\"product_id\":\"2\",\"product_name\":\"new product\",\"short_description\":\"used for training of managers\",\"full_description\":\"used for training of managers\",\"price\":\"20000.00\",\"acct_manager\":\"rahul raja\",\"roles\":\"Manager,Manager\",\"tags\":\"abc,def\",\"skills\":\"abc,abc\",\"clients\":\"accenture,accenture,Wipro,Google\"}]"
]
so variable 'a' contains the second array
I think that the problem came from the server, your log should be like :
{
"product_id": "2",
"product_name": "new product",
"short_description": "used for training of managers",
"full_description": "used for training of managers",
"price": "20000.00",
"acct_manager": "rahul raja",
"roles": "Manager,Manager",
"tags": "abc,def",
"skills": "abc,abc",
"clients": "accenture,accenture,Wipro,Google"
}
Here is an example that illustrate what I suspected your server doing.
So as I suspected, your problem came from the server. Your server response should be like that :
[
{
"product_id": "2",
"product_name": "new product",
...
},
{
"product_id": "2",
"product_name": "new product",
...
},
...
]