display formatted json in the page

To Display formatted json we need to use <pre> tag and stringify the js object. Use JSON.Stringify JSON.stringify(value[, replacer [, space]]) Parameters value The value to convert to a JSON string. replacer If a function, transforms values and properties encountered while stringifying; if an array, specifies the set of properties included in objects in the…

Converting Nested Json files to CSV in java with reflection

Objective: convert nested json to csv. The csv header should contain fields from each level and separated by ‘_’. Example: Header should become: firstName, lastName, isAlive, age, address_streeAddress, address_city, address_state, address_postalCode, phoneNumbers_type….etc Actions: 1. deserialize the json to the mapped java object using gson or jackson. 2. append header first using reflection 3. append values with…

Spring 4 MVC ContentNegotiatingViewResolver example

This article demonstrates supporting multiple output formats for your Spring 4 MVC application using Spring’sContentNegotiatingViewResolver. We will be generating application output in XML, JSON, PDF, XLS and HTML format, all using Annotation based configuration. ContentNegotiatingViewResolver is an implementation of ViewResolver, which uses the requested media type (based on filetype extension, URL parameter specifying type of…

spring config custom httpMessageConverter

in spring 4.1.2, the GsonHttpMessageConverter is added so that we could use it to replace the jackson converter for json serialization and deserialization. To added it, we could config our own RequestMappingHandlerAdapter and add the gson one to the “messageConverters” field. Also we would have to add bean validator for the RequestMappingHandlerAdapter. By doing this, i got several validation…

Angular’s $scope event system $emit, $broadcast and $on

Angular’s $emit, $broadcast and $on fall under the common “publish/subscribe” design pattern, or can do, in which you’d publish an event and subscribe/unsubscribe to it somewhere else. The Angular event system is brilliant, it makes things flawless and easy to do (as you’d expect!) but the concept behind it isn’t so simple to master and…

google spreadsheet api json xml html

It is not that straight forward to get the xml/json/html outpt for  a google spreadsheet.    HTML First thing we need to do is to publish the sheet under File -> publish to the web…. Here is what you may gethttps://docs.google.com/spreadsheets/d/YOUR-SHEET_ID/pubhtml Now you have the html version.  XML/JSON  After you get the shee-id, what you…

parse json file in android from asset

1. The JSON Structure I am taking an example of following JSON which will give you list of employees and each employee will have details like id, name, city, gender, age etc. Consider that above JSON data is stored in jsondata.txt file which is stored in assetsfolder. 2. Reading Text File (from assets folder) Before we start parsing…

convert string to json object

In JS To convert a JSON text into an object, you can use the eval() function. eval() invokes the JavaScript compiler. Since JSON is a proper subset of JavaScript, the compiler will correctly parse the text and produce an object structure. The text must be wrapped in parens to avoid tripping on an ambiguity in…