# What value is missing in my JSON parse?

**URL:** <https://discourse.processing.org/t/what-value-is-missing-in-my-json-parse/37483>\
**Category:** Coding Questions\
**Created:** [June 11, 2022, 8:32pm UTC](https://discourse.processing.org/t/what-value-is-missing-in-my-json-parse/37483 "2022-06-11T20:32:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gis667](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gis667/32/16453_2.png) [@gis667](https://discourse.processing.org/u/gis667)\
**Post date:** [June 11, 2022, 8:32pm UTC](https://discourse.processing.org/t/what-value-is-missing-in-my-json-parse/37483/1 "2022-06-11T20:32:55Z")

</div>

I’m working on building two programs, one in Python and one in Processing, to communicate over socket TCP / data stream.

75% is working perfectly:

- Encoding JSON and sending over socket from Processing
- Receiving message and decoding JSON in Python
- Encoding JSON and sending over socket from Python

What is giving me trouble is parseJSONObject() in Processing:

[reference: parseJSONObject()](https://processing.org/reference/parseJSONObject_.html)

Python originally builds the following string:

**Python**

```auto
msgPayload = {}
msgPayload['dataReq'] = True
msgPayload['captureCount'] = commHandler.imageCaptureCount
msgPayload['flatHash'] = commHandler.hashFlat
msgPayload['tbBlue'] = commHandler.tbDialogue
msgPayload['tbGrey'] = commHandler.tbGrey
msgPayload['tbFight'] = commHandler.tbFight

jsonObj = jsonpickle.encode(msgPayload)
jsonDumpStr = jsonpickle.dumps(jsonObj)

print(jsonDumpStr)

"{\"dataReq\": true, \"captureCount\": 0, \"flatHash\": false, \"tbBlue\": false, \"tbGrey\": false, \"tbFight\": false}"

```

However, attempting parseJSONObject() on the received string failed because:

**Processing**

```auto
"{\"dataReq\": true, \"captureCount\": 0, \"flatHash\": false, \"tbBlue\": false, \"tbGrey\": false, \"tbFight\": false}"
java.lang.RuntimeException: A JSONObject text must begin with '{'

```

So, I trimmed the string in python to remove the quotes from the encoded bytes:

**Python**

```auto
jsonDumpStrTrimmed = jsonDumpStr[1:(len(jsonDumpStr)-1)]
jsonDumpBytes = jsonDumpStr.encode('UTF-8')

```

This still results in a failed pasreJSONObject() in Processing because:

**Processing**

```auto
if (myClient.available() > 0) { 
  raw = myClient.readString();
  print(raw);
    
  JSONObject json = parseJSONObject(raw);

{\"dataReq\": true, \"captureCount\": 0, \"flatHash\": false, \"tbBlue\": false, \"tbGrey\": false, \"tbFight\": false}
java.lang.RuntimeException: Missing value

```

I must be missing something _reaaaally_ fundamental because I don’t see any missing values or foobar JSON encoding. Help?

---

<div class="post-metadata">

**Author:** ![gis667](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gis667/32/16453_2.png) [@gis667](https://discourse.processing.org/u/gis667)\
**Post date:** [June 12, 2022, 1:28am UTC](https://discourse.processing.org/t/what-value-is-missing-in-my-json-parse/37483/2 "2022-06-12T01:28:18Z")

</div>

My buddy and I found the root cause. jsonPickle.encode() and .dumps are essentially the same thing, so I was encoding my data twice. I removed the encode() function in Python and Processing can parse successfully.
