import socket
import json

HOST = '127.0.0.1'    # The remote host
PORT = 13              # The same port as used by the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    # s.sendall(b'Hello, world')
    data = s.recv(1024)
print('Received', repr(data))
j = json.loads(data)
print(json.dumps(j, indent=4, sort_keys=True))

import socket
import json

send_data = {}
send_data['category'] = 'fun'
send_data['bla'] = 'blub'
send_j_data = json.dumps(send_data)
print 
HOST = '127.0.0.1'    # The remote host
PORT = 13              # The same port as used by the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall((len(send_j_data)).to_bytes(2, byteorder='big'))
    s.sendall(send_j_data.encode())
    # data = s.recv(1024)
# print('Received', repr(data))
# j = json.loads(data)
# print(json.dumps(j, indent=4, sort_keys=True))

Use python script to send json
Use python script to send json

  import socket
  import json
  
+ send_data = {}
+ send_data['category'] = 'fun'
+ send_data['bla'] = 'blub'
+ send_j_data = json.dumps(send_data)
+ print 
  HOST = '127.0.0.1'    # The remote host
  PORT = 13              # The same port as used by the server
  with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
      s.connect((HOST, PORT))
-     # s.sendall(b'Hello, world')
+     s.sendall((len(send_j_data)).to_bytes(2, byteorder='big'))
+     s.sendall(send_j_data.encode())
-     data = s.recv(1024)
+     # data = s.recv(1024)
- print('Received', repr(data))
+ # print('Received', repr(data))
- j = json.loads(data)
+ # j = json.loads(data)
- print(json.dumps(j, indent=4, sort_keys=True))
+ # print(json.dumps(j, indent=4, sort_keys=True))
  
Use python script to send json
## Code Before:
import socket
import json

HOST = '127.0.0.1'    # The remote host
PORT = 13              # The same port as used by the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    # s.sendall(b'Hello, world')
    data = s.recv(1024)
print('Received', repr(data))
j = json.loads(data)
print(json.dumps(j, indent=4, sort_keys=True))

## Instruction:
Use python script to send json
## Code After:
import socket
import json

send_data = {}
send_data['category'] = 'fun'
send_data['bla'] = 'blub'
send_j_data = json.dumps(send_data)
print 
HOST = '127.0.0.1'    # The remote host
PORT = 13              # The same port as used by the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall((len(send_j_data)).to_bytes(2, byteorder='big'))
    s.sendall(send_j_data.encode())
    # data = s.recv(1024)
# print('Received', repr(data))
# j = json.loads(data)
# print(json.dumps(j, indent=4, sort_keys=True))
