How to add new line in JSON Script in Obsidian - javascript

So, I tried to edit the JSON file of OMDb API script that created by Christian B. B. Houmann. There's one interesting part of the script, it's the one who can split the Links that have been retrieved from the API.
actorLinks: linkifyList(selectedShow.Actors.split(",")),
It would result in Obsidian like these :
actor:: [[Michelle Yeoh]], [[Stephanie Hsu]], [[Ke Huy Quan]]
But the thing is, I want the result to be like this:
actor:: [[Michelle Yeoh]]
actor:: [[Ke Huy Quan]]
actor:: [[Stephanie Hsu]]
So, it wanted the actors splited by new lines and by actor string.
The reason? It will help me to organize my Metadata in Obsidian.
I'm not a programmer.. but i have doing this.. add \n in the split string. It didn't work lol. Is there anything that I can do?

Related

AngularJS/JavaScript - How to rename an array key name

I have an application that reads an excel file, and displays its contents in an html table.
These elements are in an array called "AgendaItems".
There are 2 files the user can read, each is formatted with some differences.
Both have 3 columns.
File 1: AgendaItem, LegistarId, Title
File 2: Agenda #, File #, Title
I am able to read the file and populate the array $scope.AgendaItens with the contents of either file, depending what the user selects.
My problem is that before making these modifications to accept a second file with a different format, I used:
<td scope="row">{{ai.AgendaItem}}</td>
<td>{{ai.LegistarID}}</td>
When processing the new file, now the array contains: Agenda #, and File #, which are equivalent to AgendaItem, and LegistarID respectively.
Is there a way to, in the HTML choose which value to display? for example, if array has AgendaItem, display AgendaItem, if array has Agenda #, display Agenda #?
Or, is it possible to rename a the name of a key, from Agenda # to AgendaItem and from File # to LegistarID?
Please let me know if I need to post more details, more code in order for me to be able to get help.
Thank you in advance,
Erasmo
You can use javascript array.map extension ? May be better for later reading the code.
Source data
var source = [{"Agenda #":"1","File #":"file1.xls"}]
Map it for cleaner usage
var maped = source.map(function(p) {
return {"AgendaItem":p["Agenda #"], "LegistarID":p["File #"]}
})
Other wise you have to use Object[fieldName] usage in html.(not suggesting to do so) like; ng-if="expression"
< ... ng-if='data["Agenda #"]' > {{data["Agenda #"]}}
...

Scrapy: Converting Javascript array to Json on Python

I have been struggling with a site I am scrapping using scrappy.
This site, returns a series of Javascript variables (array) with the products data.
Example:
datos[0] = ["12345","3M YELLOW CAT5E CABLE","6.81","1","A","N","N","N","N","N",0,0,0,0,0,"0","0","0","0","0","P","001-0030","12","40K8957","28396","250","Due: 30-12-1899",0.0000,1,"",\'\'];
datos[1] = ["12346","3M GREEN CAT5E CABLE","7.81","1","A","N","N","N","N","N",0,0,0,0,0,"0","0","0","0","0","P","001-0030","12","40K8957","28396","250","Due: 30-12-1899",0.0000,1,"",\'\'];
...
So on...
Fetching the array into a string with scrapy was easy, since the site response prints the variables.
The problem is I want to transform it into Json so I can process it and store it in a database table.
Normally I would use Javascript's function Json.stringify to convert it to Json and post it in PHP.
However when using Python's json.loads and even StringIO I am unable to load the array into json.
Probably is a format error, but I am unable to identify it, since I am not expert in Json nor Python.
EDIT:
I just realize since scrapy is unable to execute Javascript probably the main issue is that the data is just a string. I should format it into a Json format.
Any help is more than welcome.
Thank you.
If you wanted to take an array and create a json object, you could do something like this.
values = ["12345","3M YELLOW CAT5E CABLE","6.81","1","A","N","N","N","N","N",0,0,0,0,0,"0","0","0","0","0","P","001-0030","12","40K8957","28396","250","Due: 30-12-1899",0.0000,1]
keys = [x for x in range(len(values))]
d = dict(zip(keys, values))
x = json.dumps(d)
There is a section in the scrapy doc to find various ways to parse the JavaScript code. For your case, if you just need to have it in an array, you can use the regex to get the data.
Since the website you are scraping is not present in the question, I am assuming this would be a more straightforward way to get it, but you could use whichever way seems suitable.

recursively parse json in javascript to retrieve certain keys' values

I am new to javascript and every time i try learning it, I just end up in an immense amount of frustration and disgust ! No offense, but this is my opinion or perhaps I am too stupid to not understand how it works at all.
I have a simple requirement. I have a pretty deeply nested dictionary (which is what it is called in many backend languages) at hand. To be more specific it is the raw text of a postman collection. The collection itself could have multiple nested directories.
Now all I want to do is to be able to parse this dictionary and do something with it recursively.
For example, if I had to do the same in python I would do it as simply as :
def createRequests(self, dic):
total_reqs = 0
headers = {}
print type(dic)
keys = dic.keys()
if 'item' in keys:
print "Folder Found. Checking for Indivisual request inside current folder . . \n"
self.item_list = dic.get('item')
for each_item in self.item_list:
self.folder.append(self.createRequests(each_item))
else:
print "Found Indivisual request. Appending. . . \n"
temp_list = []
temp_list.append(dic)
self.requestList.append(temp_list)
return self.requestList
where dic would be my dictionary that I want to parse.
Is there any simple and straight forward way to do the same in Javascript?
Let's just say all I want to do is that if I have a text file that has properly formed json data in it and whose contents have been read into dataReadFromFile and then it has been converted into a JSON as :
var obj = JSON.parse(dataReadFromFile);
is there any simple and easy way to convert this JSON to dictionary or the dataReadFromFile directly into a dictionary such that I can say something like dictioanry.keys() if I wanted a list of the keys in it.
Note that the content of the file is not fixed. It may have multiple levels of nesting, which may not be known beforehand.

Issue with picking multiple JSON

I have recorded a script and "search" an id from it.
I have performed the following things
Have parametrize the "searcID" so that it can be picked from the "CSV_Data Config"
Have extracted the "key" from the URL through "Regular Expression Extractor" to provide it to the desired URL requiring "key", so that it can be dynamic
Now the issue is, since the script is recorded for one search id, in "/build-4.4.10.0/SECChecker/Search/Html?_dc=0.5557150364018139&Grid-Ajax", the last line of my script has a body of the one recorded "searchId".
The script runs and return for each thread this same result of JSON (that is present in the last line i mentioned), i want this too to be dynamic, how can i do that? Please guide
If you want to parametrize the last request, you should use the following notation: ${"var name"} and use a CSV manager. link2
for instance, if you want to parametrize the fist param of the body you should have something like this:
{"SortField":"${var_name}",....
One thing, the dc param, part of the path, looks like a random used to avoid cache, so I use this to simulate the requests during the test:
.../Html?_dc=${__RandomString(15,0123456789)}&Grid-Ajax
This function returns a string which its length is 15 (1st param) and has a set of numbers (2nd param)
Hope It helps you.

How to convert a multiple line JSON string into a javascript object

I'm working with Google's civic info API and I'm trying to figure out how to convert a JSON repsonse into a variable javascript object (we'll call that object civicInfoObject). Then I want to display to contents of that object onto the page with HTML. I'm new to javascript and haven't been able to successfully come up with a solution or find an answer.
It's a relative big project for me so I am working in bite-size pieces. I copied and pasted the JSON response to my query and created a new HTML document with it. So basically my goal right now is to store this static JSON string in a variable (civicInfoResponse), convert it into an object and store that in a variable (civicInfoObject), and then display the contents of that object onto a page with HTML.
Here is my strategy thus far:
var civicInfoResponse = "copy-and-pasted string
that spans
multiple lines"
var civicInfoObject = JSON.parse(civicInfoResponse);
document.getElementById("Info").innerHTML = civicInfoObject;
Here is the fiddle I created so you can see the JSON response in its entirety: https://jsfiddle.net/km38o815/2/
The code I wrote might be completely wrong, I'm not sure. I'm having a hard time with my limited knowledge about javascript. Can anyone help me out or at least point me in the right direction? It would be very much appreciated. Thanks!
I updated your fiddle. If you have the JSON you should need quotes around it? is this what you are looking for?
document.getElementById("Info").innerHTML = JSON.stringify(civicInfoResponse);
https://jsfiddle.net/km38o815/7/ oops this should work now.
This question is related to: JavaScript string with new line - but not using \n
In other words, if you need the JSON to span multiple lines, use \ before starting a new line:
var civicInfoResponse = "copy-and-pasted string \
that spans \
multiple lines"
civicInfoResponseshould contain:
copy-and-pasted string that spans multiple lines

Categories

Resources