аватар question@mail.ru · 01.01.1970 03:00

How to disable the replacement of the Cyrillic alphabet with \ uxxxx in lines during conversion in json

When you try to format the JSON output using dump , Russian symbols cease to be displayed. Something like "arbitrary field, for example Address" ":" "\ u04443 \ u043b \ u0438 \ u04430 \ u041c \ u0430, etc."

n

tried json.dumps (). Encode ("UTF8" ") and codac convert - nothing helps.

n
   de   Load_Data  ( filepath ): n  ground   open  (filepath,  'r' , encoding =  'utf-8' )  as  fh: n data =" JSON.load (FH) # We download data from the file to the DATA dating  n  retu  data  def   pretty_print_json  ( data ): n inf = json.dumps (data, sort_keys =  false , indent =  4 , separators = ( '', ', ' ':' )) n  retu  inf n  
аватар answer@mail.ru · 01.01.1970 03:00

Use the parameter:

from:

if ensure_asci is true (The Default), the output is guaranteed to have alll alll alll alll Incoming Non-SCII Characters Escaped. If ensure_asci is false, these characters will be out -is.

Example:

  in [ 41 ]:  with   open  (fn,  'r' , encoding =  'utf-8' )  as  f:  ...: data = json.load (f)  ...:  Print  (json.dumps (Data,  ...: sort_keys =  false ,  ...: indent =  4 ,  ...: separators = ( ',' ,  '': ')))  ...:  { : : {  "\ u0417 \ u0430 \ u0433 \ u043e \ u043b \ u043e \ u0432 \ u043e \ u043a" :  "" \ u043f \ u0440 \ u0438 \ u043c \ u0435 \ u0440 \ u0441 \ u043b \ u043e \ u0432 \ u0430 \ u04440 \ u0444f ",   "" \ u0441 \ u043f \ u0438 \ u0441 \ u043e \ u043a "" : [  "" \ u044d \ u043b \ u0435 \ u043c \ u0435 \ u043d \ u0442 1 "" ,   "" \ u0444d \ u043b \ u0435 \ u043c \ u0435 \ u043d \ u0442 ""  ] } in [ 42 ]:  Print  (json.dumps (Data,  ...: sort_keys =  false ,  ...: indent =  4 ,  ...: ansure_ascii =  false ,  ...: separators = ( '', ', ' '': '))  ...:  {  "example" : { : ,  : [ " element 1 "" ,   "" element 2 ""  ] } }  

json file:

  {  "" example "" : { : ,  : [,  "element 2" "] } }                                       

Latest

Similar