---
title: "[WIZwiki_W7500ECO] HTTPClient with JSON parser"
url: "https://maker.wiznet.io/WIZnet/projects/%5Bwizwiki-w7500eco%5D-httpclient-with-json-parser/"
markdown_url: "https://maker.wiznet.io/WIZnet/projects/%5Bwizwiki-w7500eco%5D-httpclient-with-json-parser/md"
type: "UCC: User Created Content"
author: "Soohwan Kim"
author_url: "https://www.hackster.io/embeddist/wizwiki-w7500eco-httpclient-with-json-parser-f96641"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Soohwan Kim"
original_url: "https://www.hackster.io/embeddist/wizwiki-w7500eco-httpclient-with-json-parser-f96641"
published: "2023-04-03"
language: "en"
likes: 0
views: 100
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# [WIZwiki_W7500ECO] HTTPClient with JSON parser

> This post shows how to use HTTPClient parse Json data in ARMmbed platform.

Original author: Soohwan Kim (source: https://www.hackster.io/embeddist/wizwiki-w7500eco-httpclient-with-json-parser-f96641)

## Article

**DETAILSDescription**

This post shows how to use HTTPClient parse Json data in ARMmbed platform.

![\[WIZwiki_W7500ECO\] HTTPClient with JSON parser](https://hackster.imgix.net/uploads/cover_image/file/87929/21948839603_0d8306cc39_n.jpg?auto=compress%2Cformat&w=900&h=675&fit=min)

**Components Required**

- Wizwiki W7500 ECO

## **Story**

JSON is easy for machines to parse and generate which is based on a subset of the JavaScript Programming Language. Currently many Web Services allow to access data in JSON format. However, JSON parser is too big for low-end device as like a ARMmbed platform which has limited-resource. This post shows how to use HTTPClient parse Json data in ARMmbed platform.

![](https://hackster.imgix.net/uploads/image/file/87899/21948839603_0d8306cc39_n.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

### ** Preparation materials**

1. Software
  - JSON Parser: [MbedJSONValue libs](http://mbed.org/users/samux/code/MbedJSONValue/)
  - Ethernet Networking : [WIZnetInterface](https://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/)
  - HTTP Server with JSON : [Fraka6 Blog – No Free Lunch: The simplest python server example ![😉](https://s.w.org/images/core/emoji/11.2.0/svg/1f609.svg)](https://bitbucket.org/fraka6/mlboost/src/ce9e76218daa7bec96d61b98c9a9e90b10440b7c/mlboost/examples/server.py)

Hardware

WIZwiki-W7500ECONET: WIZwiki-W7500 + ECO Shield Ethernet

![](https://hackster.imgix.net/uploads/image/file/87900/22570039655_dd7e08b859_n.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

ARMmbed Board: [WIZwiki-W7500ECO](http://wizwiki.net/wiki/doku.php?id=products:wizwiki-w7500eco:start)

![](https://hackster.imgix.net/uploads/image/file/87901/22556470552_bcb48984ec_n.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

Ethernet Shield: [ECO Shield Ethernet](http://wizwiki.net/wiki/doku.php?id=products:wizwiki-w7500eco:eco-shield#eco_shield_ethernet)

![](https://hackster.imgix.net/uploads/image/file/87902/21947481954_e8193f30cb_n.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

### ** Simplest python JSON server on PC**

Modify Server IP address & port on ron_handler

```
def run(port=8000): #set port

  print('http server is starting...')
  #ip and port of server
  #server_address = ('127.0.0.1', port)
  server_address = ('192.168.0.223', port)#set port
  httpd = HTTPServer(server_address, Handler)
  print('http server is running...listening on port %s' %port)
  httpd.serve_forever()
```

Modify JSON form in do_GET handler

```
#handle GET command
def do_GET(self):
  if format == 'html':
      self.send_response(200)
      self.send_header("Content-type", "text/plain")
      self.send_header('Content-type','text-html')
      self.end_headers()
      self.wfile.write("body")
  elif format == 'json':
      #self.request.sendall(json.dumps({'path':self.path}))
      #self.request.sendall(json.dumps({'pi':3.14}))
      self.request.sendall(json.dumps({'name':'John snow', 'age': 30, 'gender':'male'}))
  else:
      self.request.sendall("%st%s" %('path', self.path))
  return
```

Execute json_server

Excute json_server

![](https://hackster.imgix.net/uploads/image/file/87903/22570506275_5aaffdfe91_b.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

Test by using curl

```plaintext
 $>curl ip_address:port_number
```

![](https://hackster.imgix.net/uploads/image/file/87904/22557012682_d434b65e5f_z.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

### ** Make main.cc**

- Source Code@<https://developer.mbed.org/users/embeddist/code/Simple_HTTPClient_JSON/wiki/Homepage>

Network Configration for WIZwiki-W7500ECO

```plaintext
// Enter a MAC address for your controller below.
 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};

 printf("initializing Ethernetrn");
 // initializing MAC address
 eth.init(mac_addr, "192.168.0.34", "255.255.255.0", "192.168.0.1");

 // Check Ethenret Link
 if(eth.link() == true)   printf("- Ethernet PHY Link-Done rn");
 else printf("- Ethernet PHY Link- Failrn");

 // Start Ethernet connecting: Trying to get an IP address using DHCP
 if (eth.connect()<0)    printf("Fail - Ethernet Connecing");
```

TCP connect to simple python JSON server

```plaintext
 sock.connect("192.168.0.223", 8000); // "destination IP address", destination port number
```

Make Get form in HTTP format

```plaintext
 snprintf(http_tx_msg, http_tx_msg_sz,  "GET / HTTP/1.1rnHost: 192.168.0.223:8000rnUser-Agent: WIZwiki-W7500ECOrnConection: closernrn");
```

TCP Send Get form

```plaintext
 sock.send_all(http_tx_msg, http_tx_msg_sz-1); // tx_buf, tx_buf_size
```

TCP Recv data in JSON format

```plaintext
 while ( (returnCode = sock.receive(http_rx_msg, http_rx_msg_sz-1)) > 0) {
         http_rx_msg[returnCode] = '';
         printf("Received %d chars from server:nr%sn", returnCode, http_rx_msg);
     }
```

1. Do JSON parse

```plaintext
 parse(parser, http_rx_msg);
```

1. Output the parsed data

```plaintext
 // parsing "string" in string type
 printf("name =%srn" , parser["name"].get<string>().c_str());
 // parsing "age" in integer type
 printf("age =%drn" , parser["age"].get<int>());
 // parsing "gender" in string type
 printf("gender =%srn" , parser["gender"].get<string>().c_str());
```

### ** Demo. HTTPClient with JSON parser**

1. 1. Network config.
  2. Confirm Received JSON data
  3. Print-out the pasing data

![](https://hackster.imgix.net/uploads/image/file/87905/22557404802_8bfb5be6a2_c.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

### ** Packet Capture**

1. 1. TCP-Connection
  2. Target board sends GET Form to simple python JSON server
  3. simple python JSON server sends JSON data to Target board

![](https://hackster.imgix.net/uploads/image/file/87906/22545387906_f80e69cab6_b.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

---

Source: https://maker.wiznet.io/WIZnet/projects/%5Bwizwiki-w7500eco%5D-httpclient-with-json-parser/
