I'm using vscode format on save feature and it was working great. but now it is forcing to insert a line break when using Square Brackets for arrays [ ] on objects. Like:
If I try to write this:
{
"response": {
"status": 200,
"property": ["response"]
}
}
When I hit Ctrl+S to save, it formats the code to:
{
"response": {
"status": 200,
"property": [
"response"
]
}
}
And I don't want that for [ ]
I disabled every setting available relate to add NewLine for both javascript. and typescript.. Any idea how to specify this?
Related
I am trying to get a Angular based frontend working, but i am having difficulty working with this format. It's html tags are in JSON format and am wondering how to output them (In Javascript/Angular). Here is a snippet (hope it works):
spans": [ { "start": 63, "end": 70, "type": "strong" } ] }, { "type": "paragraph", "text": "Notice how the tag bar transforms into a formatting toolbar when you're writing in this editor. Now, this might look like a wysiwyg, but this is actually not your average wysiwyg, as it stores structured content, and not HTML. It allows you to build your content in better ways as you type it, making it easy for you to present it in various ways later.", "spans": [ { "start": 41, "end": 59, "type": "strong" } ] }
Anybody has any experience with this? I would like to know how to "crawl" this JSON document to output (for example the spans) to HTML.
Thanks!
Just when I think I've got he hang of identifying an element in an object, I run into a scenario that I cannot seem to get the value I want.
This part works and the data returned is correct: I have a map and when I attempt to identify a building on the map, I receive the following json object (this has been shortened for readability but in real life, its properly formatted): The function MapClick(queryResults) is called when the map is clicked.
dojo.io.script.jsonp_dojoIoScript19._jsonpCallback({
"results": [
{
"layerId": 5,
"layerName": "Building",
"value": "Name of item clicked",
"displayFieldName": "name",
"attributes": {
"ID": "123",
"name": "Name of item clicked",
"Variable1": "Some bit of information",
"Variable2": "Some other bit of information",
...
...
All I'm trying to do is return either the results[0].value OR results[0].attributes.name which in this example should bring back "Name of item clicked". The layerId, layerName, value, and displayFieldName are the "common most accessed data" so they are returned but the same information is also found within the attributes.
I've tried console.log(results[1].attributes.name); and console.log(results) with no success.
Turns out the name of the function handling the MapClicked is queryResults was needed so the correct answer is: queryResults[0].value and when you see open brackets [, you can be sure you will need [ some number ] (e.g. queryResults[0].value or queryResults[99].someothervariable. Or at least I think this is a correct statement.
I have a JSON formatted text file that I'm using as kind of a database.
I read the file, use JSON.parse to turn it into an object, use delete on an element, then I JSON.stringifythe object and write it back to the file.
However the resulting file has "null" in the place where the object used to be, which isn't proper JSON, so my program will crash the next time the file is parsed. I don't like it.
How can I delete elements from my file without getting "null" where the element used to be?
Here's how I do it:
data = fs.readFileSync("./manifest/test.json");
contents=JSON.parse(data);
//some logic
delete contents.customers[i].files[j];
fs.writeFileSync("./manifest/test.json",JSON.stringify(contents,null,4));
And the resulting file before:
{
"customers": [
{
"customer": "test",
"files": [
{
"name": "test.flv",
"location": "cloudfront.url.com/check.flv"
}
]
}
]
}
And after:
{
"customers": [
{
"customer": "test",
"files": [
null
]
}
]
}
contacts.customers[i].files.splice(j, 1);
The result is still valid JSON though. JSON.parse should succeed. The error may lie elsewhere.
After lot of help from stackoverflow folks,finally resolved my json and now its looking good.
luck.json--->
{
"PERFECT_JSON_object":
{
"51b59c1bbae1c":
[
{ "id": "parties", "float_1": "0.006" , "float_2": "0.9"},
{ "id": "royal-challenge", "float_1": "0.02" , "float_2": "0.333" },
{ "id": "star-speak","float_1": "0.02","float_2":"0.1" }
],
"51b59c1bbae3c":
[
{ "id": "parties","float_1": "0.006" , "float_2": "0.9"},
{ "id": "star-speak","float_1": "0.02", "float_2": "0.009" }
],
"51b59c1bbae5c":
[
{ "id": "parties","float_1": "0.006" , "float_2": "0.9"}
]
}
}
I have been trying to get my head around d3js with json,and I must say I have progressed quite a bit.But I am still not able to get the output with json data.
I went through these link`s but dint help.
https://github.com/mbostock/d3/wiki/Requests
d3.js & json - simple sample code?
Access / process (nested) objects, arrays or JSON
MyFIDDLE with json(no output,something wrong in here)
same fiddle with some static values( without Json)--
This is the result that I want.
I know that d3.json method requires json file to be on server.For temporary basis,as the json file is small can we include it directly in a variable in our d3 script??
I think I am messing up with json data in a wrong way.Can somebody help me with it
Yes, you can just add the JSON in a variable and run it this way. See here for the updated jsfiddle. You basically just add your JSON after var data =.
I am using Solr 4 for searching in a java web application.Solr produces a JSON response from which i have to extract search results and translate them into html so user can read that.
I know one solution but it seems dumb an I think there must be intelligent ideas.
{
"responseHeader": {
"status": 0,
"QTime": 0,
"params": {
"fl": "id,title",
"indent": "true",
"q": "solr",
"wt": "json"
}
},
"response": {
"numFound": 3,
"start": 0,
"docs": [
{
"id": "1",
"title": "Solr cookbook"
},
{
"id": "2",
"title": "Solr results"
},
{
"id": "3",
"title": "Solr perfect search"
}
]
}
}
After that i eval this text as:
var obj = eval ("(" + txt + ")");
To generate html page i can use either
<script>
document.getElementById("id").innerHTML = obj.response.docs[1].id
document.getElementById("title").innerHTML = obj.response.docs[1].title
</script>
or
document.write(obj.response.docs[1].id);
But limitation is that every time solr gives response with different object structure i.e. an object may have age feild but other can not have because it depends on query.
I want to use a sigle JSP page to display search results(like Google)
for all search queries
is it possible to write a single code segment which works for any possible search results with different schema.
Javascript stops working after encountering any error which is likely in my case. that's also problem.if I use for loop to traverse the object hierarchy it is highly error -prone.
Is it possible with a single view page Thanks.
You might want to consider using ajax-solr - A JavaScript framework for creating user interfaces to Solr
I suggest using Velocity templating which is readily supported in Solr - instead of extracting data from the JSON and rendering the HTML via JS.
Docs here