简体   繁体   中英

Json invalid for perl but ok for jq

Why does the following string passes as JSON with jq but not with perl?
Example:

$ cat dummy.json | jq '.'  
{  
  "field": {  
    "customer_id": "abc"  
  },    
  "result": "processed"  
}  

But with perl fails:

$ cat dummy.json | perl -MData::Dumper -MJSON=decode_json -ne'print decode_json($_)'  
, or } expected while parsing object/hash, at character offset 1 (before "\n") at -e line 1.  

What am I messing up here?

The decoder works fine, but you're only reading one line.

Slurp the file with perl -0777

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM