Skip to content

Conversation

darind
Copy link
Collaborator

@darind darind commented Oct 10, 2019

Related to #1500

Added org.json.JSONObject.from method allowing to marshal javascript objects to the corresponding JSONObject or JSONArray.

Example:

let obj = {
    prop1: "prop1 value",
    prop2: 123,
    prop3: {
        prop4: "prop 4 value"
    }
};
let jsonObj = org.json.JSONObject.from(obj);
jsonObj instanceof org.json.JSONObject; // true

or with arrays:

let arr = [{
    prop1: "item 1 value"
}, {
    prop1: "item 2 value"
}];
let jsonObj = org.json.JSONObject.from(obj);
jsonObj instanceof org.json.JSONArray; // true

@cla-bot cla-bot bot added the cla: yes label Oct 10, 2019
@vtrifonov vtrifonov merged commit 0117448 into master Oct 10, 2019
@vtrifonov vtrifonov deleted the darind/json-objects-serialization branch October 10, 2019 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants