Skip to content

JSON.parse/stringify C APIs? #1949

@martijnthe

Description

@martijnthe

I think it would be nice if the jerry-core.h API would have C APIs that match JSON.parse/stringify.

Proposal API:

typedef jerry_value_t (*jerry_json_reviver_t) (jerry_value_t key, jerry_value_t value);

jerry_value_t
jerry_json_parse_utf8 (const jerry_char_t *utf8_str,
                       size_t str_sz,
                       jerry_json_reviver_t reviver);

typedef jerry_value_t (*jerry_json_replacer_t) (jerry_value_t key, jerry_value_t value);

jerry_value_t
jerry_json_stringify(jerry_value_t value,
                     jerry_json_replacer_t replacer,
                     jerry_value_t space);

Note the output of jerry_json_stringify is not a UTF-8 C string (jerry_char_t[]). Although in most cases you probably want a C string...:

  1. how to allocate the buffer for the C string?
  2. what's an elegant way to deal with any errors – perhaps a jerry_value_t *error_out?

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions