Representing null values in a REST API

REST is been defacto standard for serving data to external consumers. While developing such REST APIs, I have come across an interesting basic and quite common case – what to do with attributes with null values in a json response. This a very basic but a very important question and there is lot of discussion around same with so many opinions. Here is an aggregated analysis and how you can take care of this scenario in your context.

Continue reading

Nested JSON Objects with Solr

We use Solr for storing different types structured data. Solr works fine and feels intuitive to use as long as structured entity has all properties of basic types like string, number, date etc. But the moment we like to index an entity with relations (which is quite common), intuitiveness of the response will need to be compromised with. Some teams have different strategy to take care of this. We have tried different approaches and settled with a custom response writer along with a naming convention in schema. Yes, those who has to work with dynamic schema or schemaless, following wont help.

Continue reading

Tip : Problem with single and double quotes in JSON

Sometimes if your javascipt code is not working and if you are using JSON in there, may be you want to check use double and single quotes in json string.

For example check following code :


$.ajax({
url:'-----',
data:"{'username': 'Ganesh','text': 'This is test'}",
})

This code may not work because you have single quotes inside and double outside 😦 . I know this is totally something you might unexpect, but you can expect unexpected from javascript 😉

Following will work.


$.ajax({
url:'-----',
data:'{"username": "Ganesh","text": "This is test"}'
})

Best option would be create a JSON object separately and use JSON.stringify


var obj = {'username': 'Ganesh','text': 'This is test'};
$.ajax({
url:'-----',
data:JSON.stringify(obj)
})

Happy javascripting 🙂