EzDevInfo.com

jsonlint

A JSON parser and validator with a CLI. JSON Lint

SCRIPT1014: Invalid character

I have some JSON which is perfect when tested with jsonlint, but gives an Invalid character error when i try to parse it to an object. I've looked at the JSON string and it seems ok. How do I see funny characters that may be hidden??

here is the js fiddle link. http://jsfiddle.net/UexKp/


Source: (StackOverflow)

How to determine whether a string is valid JSON?

Does anyone know of a robust (and bullet proof) is_JSON function snippet for PHP? I (obviously) have a situation where I need to know if a string is JSON or not.

Hmm, perhaps run it through a JSONLint request/response, but that seems a bit overkill.


Source: (StackOverflow)

Advertisements

jQuery.getJSON callback does not fire in IE7

A valid JSON*, returned with correct HTTP headers:

Content-Type:application/json; charset=

Works in Chrome/FF, and IE7 is refusing to parse it.

Where do I look for clues?

 $.getJSON(url, null, function(data){ alert(data); /* never fires in IE7 */ });

(valid according to JSONLint )


Source: (StackOverflow)

JSON Lint throwing parsing error

JSON Lint throwing parsing error for following string. I am saying it as string because, i got this data in string format and then I generate this code. Isn't it a valid JSON? Please help

 [
        ​{
            "x": "57",
            "y": "30",
            "z": "20",
            "name": "xyz"
        },
        {
            "x": "0",
            "y": "0",
            "z": "20",
            "name": "ss"
        }
    ]

Source: (StackOverflow)

Error in parsing json Expecting '{', '['**

This is the json .

"{
    'places': [
        {
            'name': 'New\x20Orleans,
            \x20US\x20\x28New\x20Lakefront\x20\x2D\x20NEW\x29',
            'code': 'NEW'
        }

    ]
}"

I am getting json parsererror. I am checking on http://jsonlint.com/ and it shows following error

Parse error on line 1:
"{    'places': [ 
^
Expecting '{', '['

Please explain what are the problems with the json and do I correct it?


Source: (StackOverflow)

JSON returned AJAX post jQuery undefined

I am using jQuery to get a list of Names as JSON string -

`

$.ajax({ type: 'POST', url: "../Names.aspx", dataType: 'json', contentType: "application/json; charset=utf-8", data: "NAME=ALL_PROFILES", success: function (data, textStatus, jqXHR)` {

                var html = '';


                var obj = jQuery.parseJSON(data);
                $.each(obj, function (key, val) {
                    html += '<option value="' + val + '">' + val + '</option>';
                    alert("Success" + val);
                })
                $('#selName').append(html);
                $('#selName').selectmenu('refresh');


            },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert('Error ' + jqXHR.val + errorThrown.val + textStatus.val);
                }
            });

The back end is an asp.net page, and when I debug I get the string as "{"Name":["Maria","John","Raj","Rosh","Tony","Name","test3","test4","test5","test6"]}", which I put in JSONLint and validated. It returns an undefined error in the AJAX request above. If I try with a single string "Name":"John", it works perfectly. The function for adding option is not correct for an array of JSON strings(I will work on it once it enter the success block), but I don't understand why it returns an undefined error when it is returning a valid JSON string. Any help would be appreciated.


Source: (StackOverflow)

JSONLint Failed Validation

I'm plotting out some points in Google Maps, however some of the JSON isn't populating correctly. Flipping through a few of the points, i noticed that the default image wasn't populating. Chrome inspector shows that the value of the src attribute in img's that aren't working is undefined. when i run the JSON through JSONlint, it's throwing an error on a string:

"Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['";

It says that it's not, when it is. i'm sure i borked something else up and that's why it's not showing up as a string, but what? Not sure how to go forward testing this. You can check out the code here: http://jsfiddle.net/jalbertbowdenii/4Y3JF/


Source: (StackOverflow)

Json not working because of blank space

I'm trying to do a simple on click jquery on a checkbox to fill some inputs when clicked. It looks like the json response I'm receiving in the ajax request is coming with a blank space just at the start of the json string (I copied the output in notepad++ and it shows with a question mark at the begining), and so it is an invalid json (I checked it with http://jsonlint.com/) . I logged the json output in the controller just before sending it to the view and it doesn't have any blank space at the beginning, and when checked with jsonlint it shows valid. So my question is: What's the problem? How do I get rid of this blank space?

Here's my code:

View:

<input type="hidden" id="cliente_hidden" name="numero_cel" value="1"/>
<input id="titulo_factura" type="checkbox" value="" name="titulo_factura"></input>


<script language="javascript">

$(document).ready(function () {
$('#titulo_factura').click(function() {

        if ($('#titulo_factura').is(':checked')) {
            $('#titulo_factura').val('true');

                $.ajax({
                    url: 'facturacion/get_cliente/'+$('#cliente_hidden').val(),
                    dataType: 'json',                                   
                    type: 'POST',                   
                    error: function(){
                        alert('failure');
                    },
                    success: function(data) {
                        //alert($('#same_contact').val());
                        $('#nombre').val(data.nombre);
                        $('#cedula').val(data.cedula);
                             $('#cities2').val(data.ciudad_fact);
                        $('#states2').val(data.estado_fact);
                        $('#country2').val(data.pais_fact);
                        $('#txta_dir').val(data.direccion_fact);
                        $('input.tel_cel').val(data.num_mov);
                        $('input.numero_cel').val(data.numero);
                    },
                });
            }   
        });
});
</script>


Controller:

class Facturacion extends CI_Controller {

function get_cliente($cliente){
    $this->load->model('client_model');
    $result = $this->client_model->get_cliente_completo($cliente)->row();

    $data['nombre'] = $result->primer_nombre .' '.$result->segundo_nombre.' '.$result->primer_apellido.' '.$result->segundo_apellido;
    $data['cedula'] = $result->cedula;
    $data['ciudad_fact'] = $result->id_ciudad_env;
    $data['estado_fact'] = $result->id_estado_dir_env;
    $data['pais_fact'] = $result->id_pais_dir_env;
    $data['direccion_fact'] = $result->direccion_env;
    $data['cod_mov'] = $result->cod_mov;
    $data['numero'] = $result->num_mov;

    header('Content-Type: application/json');
    $json = json_encode($data);
    log_message('debug', 'JSON OUTPUT:'.$json);
    echo $json;
}
}


Model:

class Client_model extends CI_Model {

function get_cliente_completo($cliente){

        $query = $this->db->query('select c.id_cliente, c.cedula, c.pasaporte, c.primer_nombre, c.segundo_nombre, c.primer_apellido, c.segundo_apellido
        , t.codigo as "cod_loc", t.numero as "num_loc", ot.codigo as "cod_mov", ot.numero as "num_mov", c.fecha_nac, c.direccion_env
        , c.venc_pasaporte, c.email1, c.preferencia_asiento, c.email2, 
        lnc.id_lugar as "id_ciudad_nac", lnc.nombre as "ciudad_nac", lne.id_lugar as "id_estado_nac", lne.nombre as "estado_nac"
        , lnp.id_lugar as "id_pais_nac", lnp.nombre as "pais_nac",      
        lec.id_lugar as "id_ciudad_env", lec.nombre as "ciudad_dir_env", lee.id_lugar as "id_estado_dir_env", lee.nombre as "estado_dir_env"
        , lep.id_lugar as "id_pais_dir_env", lep.nombre as "pais_dir_env"
            from cliente_particular c, telefono t, telefono ot, lugar lnc, lugar lne, lugar lnp, lugar lec, lugar lee, lugar lep,
            lugar lfc, lugar lfe, lugar lfp 
                where c.id_cliente = t.fk_client_part
                    and t.codigo = \'212\' and ot.codigo not like \'%212\'
                    and c.id_cliente = ot.fk_client_part 
                    and c.fk_lugar_nac = lnc.id_lugar and lnc.fk_padre = lne.id_lugar and lne.fk_padre = lnp.id_lugar
                    and c.fk_lugar_dir_env = lec.id_lugar and lec.fk_padre = lee.id_lugar and lee.fk_padre = lep.id_lugar
                    and id_cliente = '.$cliente.';');

    return $query;          
}
}

Source: (StackOverflow)

FATAL ERROR: JS Allocation Failed - process out of memory

I'm trying to run jsonlint on a 40MB JSON file, but it halts execution with an exit status of 5, and the following error message:

FATAL ERROR: JS Allocation Failed - process out of memory

Does anyone know how I can get this JSON pretty-printed? I wonder if it has to do with node's --max-old-space-size argument, but I'm also unsure how to pass this to the installed executable file.

If there's another approach I could take to rendering this with human-readable indentation, I'd appreciate those suggestions, too.


Source: (StackOverflow)

Invalid Json Error in JsonLint

I have a web service returning following json:

[
    {
        "id": "9469",
        "title": "A person grabbed by police because being Nigerian he was carrying a Ghanaian passport!",
        "introtext": "A person has grabbed by police because being Nigerian he was having a Ghanaian passport! 

An individual has gotten by police on the grounds that being Nigerian he was having a Ghanaian visa! 

A 29-year-old Nigerian has been captured for endeavoring to get a visa with a falsely acquired Ghanaian travel permit."
    }
]

JSONLint is giving following error:

Parse error on line 5:
...       "introtext": "A person has grabbe
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

I am really unable to understand what is making json invalid here? Is it newline or what? What can I do to make it work? Thanks.


Source: (StackOverflow)

Mongodb retrieve correct json from geospatial query php

I'm tring to retrieve correct JSON from this code.

$query = array( 'loc' => array('$geoWithin' => array('$centerSphere' => array(array($x,$y), 35 / 6371) )));
    $cursor = $collection->find($query);

    // How many results found
    $num_docs = $cursor->count();

    if( $num_docs > 0 )
        {
          foreach($cursor as $doc['punti'])
               echo json_encode($doc);
            }
        }
    else
    {
        echo "NO LOCATION \n";
    }

if i try to validate result in http://jsonlint.com/ it shows error.

i'll post the result of query:

{
    "punti": {
        "_id": {
            "$id": "551fb585ecba12c819000032"
        },
        "nome": "Google",
        "loc": [
            -122.083983,
            37.422969
        ],
        "icona": 1,
        "istituzione_id": {
            "$id": "551fb556ecba12c819000031"
        }
    }
}{
    "punti": {
        "_id": {
            "$id": "5520fe2becba12c003000029"
        },
        "nome": "Oracle",
        "loc": [
            -122.262168,
            37.531595
        ],
        "icona": 1,
        "istituzione_id": {
            "$id": "551fb556ecba12c819000031"
        }
    }
}

the error in JSONLint is about:

Parse error on line 16:
...1"        }    }}{    "punti": {   
--------------------^
Expecting 'EOF', '}', ',', ']'

I've tried different ways, without reaching any solution.Can Someone help me ?


Source: (StackOverflow)

Parsing JSON with jQuery's ajax method

I'm currently fiddling around with JSON - but I can't get jQuery's $.ajax method to parse my feed.

I've validated the feed with JSONLint, and the JS with JSLint - it appears to be fine.

Check out my jsfiddle-example here: http://jsfiddle.net/timkl/RqgRf/

Any hint on what could be wrong is highly appreciated :)


Source: (StackOverflow)

Problems on Both Parsing Legal JSON [closed]

I have a problem on both parsing legal and validated JSON objects.

This one runs okay

var response = {"tags":"[{\"value\": 2,\"label\": \"Dubstep\"},{\"value\": 3,\"label\": \"BoysIIMen\"},{\"value\": 4,\"label\":\"Sylenth1\"}]"};

var tags = $.parseJSON(response.tags);
console.log(tags);

It Prints Out on the Console Array[3]

but when I run I change the value of var response to this one

 var response = {"tag":"[{\"id\":2,\"name\":\"Dubstep\",\"description\":\"Dub wob wob\"},{\"id\":3,\"name\":\"BoysIIMen\",\"description\":\"A 1990s Boy Band\"},{\"id\":4,\"name\":\"Sylenth1\",\"description\":\"A VST Plugin for FLStudio \"}]"};

the value of tags is null take note that both values are validated on JSONLint.


Source: (StackOverflow)

JSON unexpected token error (PHP json_encode & jsonlint.com)

{"cover":"http:\/\/files.domain.com\/some_file\/1234.jpg_thumb.png"}

This is my JSON code and when I tries to parse, it returns Unexpected Token error. I checked on http://jsonlint.com/ but it didn't go well.

I used php json_encode function to encode JSON.

++ update It works fine when I copy JSON string and paste it in Notepad or other plain text editors and re-copy that. I think it must be some encoding error or something. I'll try.


Source: (StackOverflow)

Why is this JSON invalid?

{
    "already_public": "null",
    "status": "true",
    "message": "Service provider added successfully",
    "detail": {
        "id": "1175",
        "address_1": "",
        "address_2": "",
        "profession": "Accountant",
        "city": "",
        "company": "",
        "email_1": "",
        "email_2": "",
        "firstname": "das\' feet",
        "lastname": "",
        "life_block": "Family",
        "work_phone": "",
        "mobile_phone": "",
        "home_phone": "",
        "fax": "",
        "state": "",
        "title": "",
        "website": "",
        "zip": "",
        "ismyprovider": "1",
        "privacy": "null",
        "img_url": "http://localhost/mtube/uploads/blank_pic.png"
    },
    "inresponseto": "addServiceProvider"
}

Everything is ok except for this line

"firstname": "das\' feet"

It has a single quote within double quote. Despite having a \ before the character this json is being invalidated by jsonlint.


Source: (StackOverflow)