GWT Label format Object String - json

I have an String representation of an object obtained from reflectionToString method (http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/builder/ToStringBuilder.html#reflectionToString%28java.lang.Object%29) and I need to put it into a GWT Label. But this string could be very long and I wanted to display it in a nice format, ideally in json format.
Anyone has any suggestions on how to format it?

You could use something like http://highlightjs.org/ to format the raw text/code in a vaguely human readable way? Calling JS from GWT is pretty easy.

Related

Sending Json looking formatted plain text to be de-serialized

If you send plain Json formatted un-serialized text from a web api and have it be de-serialized in a C# function using the jsonConvert.DeserializeObject functional? I have a co-worker who created a web api in the cloud and he sends plain text formatted to look like un-serialized Json which I try to use C# functionality to Deserialize but when I try to convert what is sent into Model classes it fails. I am telling him that the C# JsonConvert.SerializeObject must be used or it won't work. Can someone help clarify this with me?
Your colleague is right. JSON strings need to be de-serialized to turn them into objects.
Moreover, the things you call "plain text formatted to look like JSON" are JSON strings. JSON is plain text (in UTF8, with syntax rules).
Let's say you have some data structure in your program that you want to send over the network. The network can only send series of bytes, so whatever your structure was, you need to turn it into that -- you need to serialize it. JSON is one way of doing that, e.g.
'{"example": "some data"}'
is a string containing JSON. It is serialized, it's just a string of bytes to send over the network.
On the receiving end, you need to deserialize it back into some data structure, some type of hash map or dictionary or whatever it's called in C# probably.
If what you try "fails", you could ask a much more specific question showing what you tried with what data and how exactly it failed.

How do I convert the following data serialization format into POJO or JSON?

I was expecting a JSON string while testing an API using Postman, but instead got this:
{city=Shanghai, work=112-454-7895, fax=788-899-7899}
Obviously I cannot put that into Google and ask what format is it, hence I am asking it here. Postman also says it is a 'bad string'.
I have never seen the above data serialization format. If someone can point the format out to me I would be able to find and use a converter. Additional suggestion with converting it to POJO or JSON are welcome as well.
I figured out that the above format is a stringified version of a HashMap<String, String>, and that there is no direct way to convert it into JSON/POJO. Converting it into json string requires additional work but is fairly straightforward.

Javascript in place of json input step

I am loading data from a mongodb collection to a mysql table through Kettle transformation.
First I extract them using MongodbInput and then I use json input step.
But since json input step has very low performance, I wanted to replace it with a
javacript script.
I am a beginner in Javascript and even though i tried somethings, the kettle javascript script is not recognizing any keywords.
can anyone give me sample code to convert Json data to different columns using javascript?
To solve your problem you need to see three aspects:
Reading from MongoDB
Reading from JSON
Reading from (probably) String
Reading from MongoDB Except if you changed the interface, MongoDB returns not JSON but BSON files (~binary JSON). You need to see the MongoDB documentation about reading and writing BSON: probably something like BSON.to() and BSON.from() but I don't know it by heart.
Reading from JSON Once you have your BSON in JSON format, you can read it using JSON.stringify() which returns a String.
Reading from (probably) String If you want to use the capabilities of JSON (why else would you use JSON?), you also want to use JSON.parse() which returns a JSON object.
My experience is that to send a JSON object from one step to the other, using a String is not a bad idea, i.e. at the end of a JavaScript step, you write your JSON object to a String and at the beginning of the next JavaScript step (can be further down the stream) you parse it back to JSON to work with it.
I hope this answers your question.
PS: writing JavaScript steps requires you to learn JavaScript. You don't have to be a master, but the basics are required. There is no way around it.
you could use the json input step to get the values of this json and put in common rows

String XML to JSON conversion in .NET without using XmlDocument

I'm trying to find a more memory efficient solution for converting XML string to JSON string (and vice versa)
without using XmlDocument.
Currently, all 3rd party libraries i tried, expects XmlDocument as input.
Before I'm writing my own parser using XmlReader, i was wondering if anyone know of a out of the box solution?
What are you trying to do exactly: Generate JSON directly from XML or deserialize the XML string to an object and then serialize it to JSON?
If you need a XmlSerializer take a look into this one I created (it uses XmlReader internally), you can find the code and how to use it here:
XML serialization using Generics
I ended up writing my own thin LightXmlDocument which holds a tree of objects representing xml elements.
LoadXml method implemented using XmlReader, i'm reading the xml string and building the tree.
Tested with 10 threads each thread iterating 900 times over different xml sizes:

Convert loaded string to Object

In AS3, I want lo load a file text with URLLoader. In the file text I have the following string:
{a:1,b:"string",c:["one","two"]}
Is it possible (once loaded) to convert it to an Object?
There is no intrinsic deserializer built into the language, no. But if your text file sticks to the JSON standard, then you could use a JSON parser to do the conversion for you: http://code.google.com/p/as3corelib/source/browse/#svn%2Ftrunk%2Fsrc%2Fcom%2Fadobe%2Fserialization%2Fjson
Or, if you cannot adhere to JSON, you could always write your own deserializer.
What you need is to eval the string to create the object.
This is done natively in javascript and AS2. AS3 however does not support this function.
But all is not lost. The people at Hurlant have created a library that does this "almost" as good as native JavaScript.
Here is a good example.
And another library example using d.eval
I would like to point out though that if you have accept to the source of the object string that you create a JSON object out of it. The JSON libraries are usually much easier and more reliable to use then the libraries that do Eval.
Your string is a sting with JSON format. Use JSONDecoder to decode it to an Object, like this:
var dc:JSONDecoder = new JSONDecoder("{a:1,b:'string',c:['one','two']}");
var ob:Object = dc.getValue();