Skip to content

Commit 5676d31

Browse files
committed
Remove to_object function. Functionality is similar to JMESPath community from_items function
1 parent 6f4af98 commit 5676d31

File tree

3 files changed

+0
-41
lines changed

3 files changed

+0
-41
lines changed

README.md

-18
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,6 @@ range(1, 5) // [1, 2, 3, 4]
241241
range(1, 5, 'item_') // ["item_1", "item_2", "item_3", "item_4"]
242242
```
243243
244-
### `to_object`
245-
**Syntax**:
246-
```jmespath
247-
to_object(entries)
248-
```
249-
250-
**Description**:
251-
Converts an array of key-value pairs into an object.
252-
253-
**Example**:
254-
```jmespath
255-
to_object([['key1', 'value1'], ['key2', 'value2']])
256-
// { "key1": "value1", "key2": "value2" }
257-
258-
[ 'value1', 'value2'] | to_object(zip(range(1, length(@) + 1, 'key'), @))
259-
// { "key1": "value1", "key2": "value2" }
260-
```
261-
262244
### `json_serialize`
263245
**Syntax**:
264246
```jmespath

src/Runtime.ts

-12
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,6 @@ export class Runtime {
657657
return Array.from({ length: end - start }, (_, i) => (prefix !== undefined ? `${prefix}${i + start}` : i + start));
658658
};
659659

660-
private functionToObject: RuntimeFunction<[JSONArrayKeyValuePairs], JSONObject> = ([array]) => {
661-
return Object.fromEntries(array);
662-
};
663-
664660
private functionJsonSerialize: RuntimeFunction<[JSONValue], string> = ([inputValue]) => {
665661
const result = jsonStringify(inputValue);
666662
if (result === undefined) {
@@ -1177,14 +1173,6 @@ export class Runtime {
11771173
},
11781174
],
11791175
},
1180-
to_object: {
1181-
_func: this.functionToObject,
1182-
_signature: [
1183-
{
1184-
types: [InputArgument.TYPE_ARRAY],
1185-
},
1186-
],
1187-
},
11881176
json_serialize: {
11891177
_func: this.functionJsonSerialize,
11901178
_signature: [

test/jmespath-functions.spec.ts

-11
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,6 @@ describe('Added functions', () => {
150150
expect(search({}, "range(1, 5, 'item_')")).toEqual(['item_1', 'item_2', 'item_3', 'item_4']);
151151
});
152152

153-
it('to_object()', () => {
154-
expect(search({}, "to_object([['key1', 'value1'], ['key2', 'value2']])")).toEqual({
155-
key1: 'value1',
156-
key2: 'value2',
157-
});
158-
expect(search(['value1', 'value2'], "to_object(zip(range(1, length(@) + 1, 'key'), @))")).toEqual({
159-
key1: 'value1',
160-
key2: 'value2',
161-
});
162-
});
163-
164153
it('json_serialize()', () => {
165154
expect(search({ foo: 'bar' }, 'json_serialize(@)')).toEqual('{"foo":"bar"}');
166155
});

0 commit comments

Comments
 (0)