how to parse javascript object with undefined as string in python - javascript

Im trying to scrape a website for the javscript objects it contains. Im trying to load them as python dictionary.
However, I can't just pass the javascript object in json.loads because it contains undefined as values. How can we load javascript object from strings to python dictionaries?

Related

Comprehending Java's HashMap in Javascript as a JSON object

I have an application where a Java HashMap is sent over via HTTP protocol, and I have to comprehend that HashMap object in Javascript before appending that JSON object to MySQL database.
I have tried multiple approaches such as
Converting HashMap to String in Java code and parsing that in Javascript with JSON library
Appending raw HashMap object to MySQL.
The first approach did not work because when Java converts HashMap object to String, it strips off all quotation marks, which gives Javascript a confusion.
The second approach simply does not work.
Is there anyone with this similar experience who can give me a seamless solution?
Thanks
Solved by sending Gson object.

Convert C#.net object into json using js

I'm trying to convert a C#.net object into json on the client side.
I'm not sure that this is even possible...
I know that the object has been serializable with BinaryFormatter class.
Is it possible ? or i'm wasting my time on it.

Pass a java array to javascript

In my app I have an array and I want to pass this array to a javascript script to display an html list.
My app generate this array after reading information from JSON and I need to pass it to javascript. In iOS I used this function: stringByEvaluatingJavaScriptFromString.
How I can do the same in Android?
Use Gson library. It is an amazing JSON parsing library that can parse and create JSON arrays.
https://code.google.com/p/google-gson/
So convert your array to JSON and send it over :)

JSON file parsing issue due to javascript variables

I've been provided with a json file to show results in a tableview.
But when I tried json file validation using online json file editor then I am getting "Build tree failed" error.
I posted this message to my client about wrong json file and then he has posted some strange description which I am totally unaware.
Yes the json is not a pure json. It has javascript variables which have json variable. For now u can use a webview to evaluate the javascript variables and use the json value. For ex : dp_f : corresponds to list of departure train is a javascript array variable. U may have to eval the variable and store each array element is a new json with key as dp_f and value of array of these values
Please tell me how can I use this json file which is not pure. What is the way to parse such files ?
The only real way to evaluate JavaScript (which is really what you have, not JSON) is to evaluate JavaScript.
You will have to use some form of eval(). I recommend trying a JavaScript sandbox, if available to you. Of course the best option would be to get the data fixed.

reading a json object in jsp

i have a JSON object passed to the jsp page. it is passed as a string. now i have to parse this string and retrieve the values that are passed through the JSON object. so that i can print the values in the same jsp.
There's lots of resources, including libraries & plugins for various technologies/frameworks on json.org.
With tons of JSON parsers, it comes down to how you want to deal with data in JSON. My personal favorite from the lot is Jackson, but many others work well for simple cases too, including the "reference implementation" (aka JSON.org parser).
(I assume you want a Java parser, given reference to jsp)
My preferred solution to this problem involves using a JSON parser that provides an output that implements the java.util.Map and java.util.List interface. This allows for simple parsing of the JSON structure in the JSP Expression language.
Here is an example using JSON4J provided with Apache Wink. The sample imports JSON data from a URL, parses it in a java scriptlet and browses the resulting structure.
<c:import var="dataJson" url="http://localhost/request.json"/>
<%
String json = (String)pageContext.getAttribute("dataJson");
pageContext.setAttribute("parsedJSON", org.apache.commons.json.JSON.parse(json));
%>
Fetch the name of the node at index 1 : ${parsedJSON.node[1].name}
To make this clean, it would be preferable to create a JSTL tag to do the parsing and avoid java scriplet.
<c:import var="dataJson" url="http://localhost/request.json"/>
<json:parse json="${dataJson}" var="parsedJSON" />
Fetch the name of the node at index 1 : ${parsedJSON.node[1].name}

Categories

Resources