1. Serge Zaitsev
  2. jsmn
  3. Issues
Issue #4 resolved

how to parse more complex type (array & objects)

Anonymous created an issue

I am just loving with new json parser. It makes embedded designing a lot easier. I have one question. Would it be possible to show an example of how to parse complex tokens? For example:

js = "\"x\": \"value1\", \"y\": \"value2\", \"dsensor\": [\"s1\": 1, \"s2\": 0], \"asensor\": [\"a1\": 1.5, \"a2\": 0.8] ";

How to check the values?

check(TOKEN_STRING(js, ??????)); check(TOKEN_STRING(js, ??????)); check(TOKEN_STRING(js, ??????)); check(TOKEN_STRING(js, ??????));

Comments (5)

  1. tcousins


    I am assuming your json data stream is from a HTTP POST RESPOSE. It doesn't seem like valid json data. In any case, parsing should be easy just follow the test examples (jsmn_test.c) for the following functions: test_string() and test_partial_array()

    I think the valid json data stream should be: { "x" : "value1", "y" : "value2", "dsensor" : { "s1" : 1, "s2" : 0 }, "asensor" : { "a1" : 1.5, "a2" : 0.8 } }

    Hope that information was helpful.

  2. Anonymous

    tcousins.. your assumption is correct. The json data stream is from http post response's body. sorry for the json error. I check the test example and its still isn't clear on how to handle/parse complex data such as { "x" : "value1", "y" : "value2", "dsensor" : { "s1" : 1, "s2" : 0 }, "asensor" : { "a1" : 1.5, "a2" : 0.8 } }

    Does any have any answer for parsing complex data stream?

  3. Anonymous

    Have you found a solution to your question? I came jsmn and I was extremely excited to finally find a json parser for embedded system. However, I've read the documents and non of the given examples show how to parse a complex json string so I am wondering if you have gotten a solution?

  4. Log in to comment