Showing posts with label json. Show all posts
Showing posts with label json. Show all posts

18 February 2013

how to send json using curl?

Note:
This is for personal purpose only as reminder for future reference

This is code snippet example:
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{
"@class": "dms.pastor.model.C
ampaign",
"campaign": {
"list": {
"id": "1aa4e31ae",
"members": [{
"firstName": "Edison",
"lastName": "Trent",
"mail": "edisontrent@fake.email"
},
{
"firstName": "Casper",
"lastName": "Orillion",
"mail": "CasperOrillion@fake.email"
}]
},
"template": {
"name": "Xmas",
"source": "xmas2019.zip",
"version": "1.0"
}
}
}' http://localhost:8080/campaignprocessor/

5 November 2012

How to solve problem with Spring 3 that it return 406 instead of json object ?

Solution works for Spring 3.1

STORY

 Spring 3 come with  REST integration ,so  for example .You can  ask  Spring 3 kindly to  return JSON object? Awesome.
So you follow one of tutorials* ,but when you run example from tutorial, you see:

HTTP Status 406 -

type Status report
message
description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().

Apache Tomcat/7.0.12



which not exactly what you expected to see.
First .What Error 406 is ?

Error 406  means "Web server detects, that the data (JSON Object in our case) it wants to return is not acceptable to the client (your web browser),so  it returns a 406 error code instead.

For more detail about Error 406 : look here:  http://www.checkupdown.com/status/E406.html

According to above page:
"This error occurs very infrequently in Web browsers, because most browsers will accept any data returned from the Web server."

How lucky you are to see very very  infrequently error like that?

SOLUTION:

You just forgot add add Jackson library to your libraries

Jar can be found on this page: http://jackson.codehaus.org/

(of course normaly you will add to your maven dependencies)


Sources:

(Error 406)  http://www.checkupdown.com/status/E406.html

(Jackson JSON processor ) http://jackson.codehaus.org/

Useful tutorial for Spring 3 and JSON can be found here:
http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/

27 March 2012

how to get data from sub node in jackon library for json ?

Jackson is an AWESOME multi-purpose Java library for processing JSON data format.

STORY:
It easy to take this example:

let's say that we have a following json:
{"ground":
[{
"overground":"birds",
"underground":"worms",
}],
"house":"cottage}

to get your house, you need:

pictureNode.path("house").asText();

PROBLEM:
how to get overground that is inside ground ?

SOLUTION:
 pictureNode.path("ground").path("underground").asText();

7 October 2011

How i can add comment to json

No, you can't add comment  to JSON.

First. If you need  comment in data ,that usually means that your naming convention , design are rubbish and documentation sucks, because .... Data should be self-explanatory .

Second. It is a  data-interchange format. Devices need understand this crap,not humans.

Third. You can complain on your blogs,go to psychologist to talk about it,but  no, you can't add comment  to JSON.

So... what to do?
If you really despeard to put your /*comment*/ , then you can emulate them by add   name/pair value
like :
"__comment__" : "i am addicted from add useless comment"   which should be  ignored by your application that use the JSON data,  but comment will be visible all the time and consume your bandwith and i'm afraid is nothing what you can do about it (except do NOT use comment in first place) andI don't feel sorry about your problem.

Example:
{
  "__comment__" : "justin bieder is is good as music as I in commenting my code",

"mySkills": "rubbish",  
"your" :  "json  stuff"
}

3 October 2011

example of configuration file for elasticsearch as json

Solution for  elasticsearch 0.13.1 as JSON file (i used default values only)

If you look for YML configuration example,then go this page:
https://github.com/elasticsearch/elasticsearch/blob/master/config/elasticsearch.yml

Some general information about configuration can be found:
http://www.elasticsearch.org/guide/reference/setup/configuration.html
and here:
http://www.elasticsearch.org/guide/


{
"gateway": {
  "type": "fs", //shared file system
   "fs": {
     "location": "/opt/elasticsearch/data/cluster" //locaction of shared file system
"recover_after_nodes": 1,
"expected_nodes": 1,
"recover_after_time": "5m"
},

"cluster": {
"name": "dom"
},

"node": {
"data": true,
"master": true
},

"index": {
"number_of_shards" : 1,
"number_of_replicas" : 3
},

"bootstrap": {
"mlockall": true
},

"http": {
"enabled": true,
"port": 9200
},

"index": {
"number_of_shards": 1,
"number_of_replicas" :3
},

"node": {
"data": true,
"master": true
},
"store": {
"type": "memory",
"cacheSize": "100m",
"bufferSize": "10k"
},
"transport": {
"port": 9300,
"tcp": {
"compress": true
}
},
"routing": {
"allocation": {
"node_initial_primaries_recoveries" : 4,
"node_concurrent_recoveries": 2
}
}
}

10 March 2011

What is JSON ?

When you learning javascript or framework for javascript, you quite often see JSON in example here JSON in example.
You notice that, they are used as provide data for specified example and you feel quite screwed up, because you have no f...idea about server(or you just have no passion to install server and config because in most cases they Server which you hate it).It means that, you cannot receive data from server so you cannot using another ready-made example and only what you cand is .... screaming ... and then you ask yourself. What is JSON anyway ??

(All below information are copied (and lightly modified) from www.json.org and i put this here in case if above site is down)

JSON is acronym of JavaScript Object Notation.
It is a data-interchange format.
It is a text format that is completely language independent.(Which means it can be used in many languages,not javascript only or even in project when you don't use javascript at all)

For example between javascript and Java.

JSON is built on two structures:
A collection of name/value pairs.(In languages representation of this can be object, record, struct, dictionary, hash table, keyed list, or associative array.
An ordered list of values. (In languages representation of this can be array, vector or list).

Example of JSON forms which i usually want to use

object
single item: { string : value }
many items: { string : value , string : value , (...) , string : value }

array
single item: [ value ]
many items: [ value , value , (...) , value ]

possible values : string number object array true false null

char
any-Unicode-character
control-character
\" quotation mark
\\ character \
\/ character /
\b backspace
\f formfeed
\n newline
\r carriage return
\t tab
\u 4 hexadecimal digits


If you want to know everything about JSON (it takes whole ... 30 minutes and is translated to many languages) then go to this page:
http://www.json.org/

I will add note soon about "how to modify exists example in extjs that needed data from server to example to contain data stored in Ext itself".