Git Product home page Git Product logo

jsonerror's Introduction

jsonerror

json_decode cannot decode "[]" or "["Львів (Lviv)"]" string. It throws a "Syntax error" message. Error seems to comes from encoded file which starts with the hex "efbb bf"

Stackoverflow question : https://stackoverflow.com/questions/57409964/json-decode-cannot-decode

~/workspace/jsonerror$ php test.php
______ /fine_lviv.json ______
encoding: UTF-8
content: ["Львів (Lviv)"]
Array
(
    [0] => Львів (Lviv)
)
______ /wrong_lviv.json ______
encoding: UTF-8
content: ["Львів (Lviv)"]
PHP Fatal error:  Uncaught JsonException: Syntax error in /home/remmel/workspace/jsonerror/test.php:17
Stack trace:
#0 /home/remmel/workspace/jsonerror/test.php(17): json_decode('\xEF\xBB\xBF["\xD0\x9B\xD1\x8C\xD0\xB2\xD1\x96\xD0\xB2...', false, 512, 4194304)
#1 {main}
  thrown in /home/remmel/workspace/jsonerror/test.php on line 17

Same error with "[]" json (fine_empty.json and wrong_empty.json). The wrong file starts with "efbb bf" :

~/workspace/jsonerror$ xxd fine_empty.json
00000000: 5b5d                                     []

~/workspace/jsonerror$ xxd wrong_empty.json
00000000: efbb bf5b 5d                             ...[]

See the problem by yourself:

git clone [email protected]:remmel/jsonerror.git
cd jsonerror
php test.php

jsonerror's People

Contributors

remmel avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.